Before we start, I am using Xataface as my backend while my frontend uses the Smarty engine (something that is packaged into Xataface) to display my html code. So in the backend, the user would be uploading the photos to the system and then I would use vision to display them on the front end. If neccessary, view this http://xataface.com/documentation/how-to/how-to-handle-file-uploadsto see how to upload images using Xataface.
I am going to assume you have used method 2 to store images. If method 1 was used, I am not sure if it's possible to use this post to help you
If you've looked over the example of vision, you'll realize that you need to setup a few variables in order for it to work.
Step 1: Creating a custom action which prepares all the necessary variables needed to run the photo slide show.
The most important variable we need to set is the $imgDir variable which tells the Vision where the images you want to upload are found. We could hardcode this directory name, but hardcoding is bad. So we'll take a slightly tricky yet does the job piece of code. The images are going to be stored in a directory (depending on how you set it up based on the aforementioned document it could be anyway). To find out the exact directory you can make use of the fact that the path is stored in the table's variables.
Note in line 5 and 6, we load the table that stores the image data (in this case, I have a table called photos), and then I grab the field called photo_url which is the column in the database which saves the path of the image. That field itself is an array with lots of key=>value pairs, but the one we are interested in is called the url. Now this is the tricky part, we need to get the relative path to the directory and not the absolute path which is what the url value is (ie. site_url/tables/photos/photo_url/) But since we know that the site_url is nothing more than just the Xataface constant variable called DATAFACE_SITE_URL we can just use the php function explode to get rid of that which is what line 9 and 10 do.
After this explode function, we know that the value we need is stored in the array index 1 which is what we pass into the lsDir() function. This function is defined in the vision source code which you'll have to copy and paste into your code. I didn't post it to save room.
Now we just call the df_display() function sending in our contextual variables we need and call the photos.html file which will be parsed by the Smarty engine.
Step 2: Preparing our smarty .html page to present the slideshow
This next part gets really tricky and quite annoying. Because the vision example code integrates php code with javascript code which is just plain annoying. And anyone who has used the smarty engine knows that you have to use the {literal}{/literal} tags to parse javascript functions properly.
All I've done is taken the original example code they provided and replaced the php echo statements with the php variable. The smarty engine takes care of displaying the variable. Also, on line 8, I removed the use of the php foreach statement and utilized the Smarty foreach statement which is a little cleaner.
After this part was edited, remember to add the master.css and ie.css files. And then add the conditional comment at the top to make sure we use the ie.css file. And it should work!
Please post any errors you received and I can try to help you.
I used the {ldelim} and {rdelim} tags instead of {literal}. Both cases work
5 comments:
Thanks for this valueable post. I have read all the things very carefully, its really a helpful and effective post. I will definitely bookmark your blog
Professional Web Design
Good post. Thanks for the sharing.
Make the most out of your web design investment by choosing the right web designers and developers .
nice post ..!!!
web design services
web design
best web development company
top web development company
Webistick - Web Development & Design Company
whoah this weblog is great i love reading your posts.
Stay up the good work! You already know, a lot of persons are looking around for this info,
you could help them greatly.
Post a Comment