No-MVC Zend Framework: jQuery Star Rating code / Part IV
Before continuing (or if this doesn’t work for you), you might want to familiarize yourself with the Star Rating plugin at http://zensoftware.org/archives/483.
Add the following lines to the HEAD section of your “index.php”. This assumes that you already have one… if not, use you standard HTML template, and don’t forget to include your bootstrap
I used “loading” as a variable (as opposed to the direct output of “Error!”). You can Google the standard Ajax loading image, and put the HTML image tag in that variable to pretty things up, instead of that boring message.
BTW, I always use a leading slash and the complete path in relation to the root directory (e.g. “/images”) before each image, JS and CSS file. This way, I don’t have to worry about broken links when I split header and content sections into different files, and move them to different directories… which I favorize, because header sections are the same throughout the website, whereas content sections might use different templates.
The PHP / HTML code
You can put this code anywhere within your BODY section of your “index.php”, even in existing pages’ DIVs:
<?php $id = 1; $rating = new Mylib_Rating_Controller(); echo $rating->getRatingView($id); ?>
Set the variable “$id” to any unique id you want to rate. On my website surfspot.de, I use it to rate a page, so the id comes from my database, and represents the page id. If you have more than one rating on one page, say for a couple of images, instantiate the class once, and only use
echo $rating->getRatingView($id) with a different id for each image.
Next up: The jQuery Ajax receiver