Tuesday, December 15, 2009

Rating system for ZendFramework with Jquery

This ain't going to be mind blowing article, because its one of the very first blog post of mine which will explain how i got some task done. as this is the very beginning i wanted to select a small task to cover up in a blog post.

well i had to write a nice rating module for a small CMS which was written in Zend Framework.

so first i had to find a nice JavaScript rating code and then to write the PHP back-end to make it functioning.

so the only thing which got my eye was a jquery plugin which looked nice and it had lot of customization options as well.

and then it was the time for me to change this into a Zend Framework view helper. so here are the steps i took.

1. The view helper class

The view helper class will be needed so you will be able to call the rate module to render the rating control from any place of your site. this file should reside in folder Library/View/Helper.

2. The template(phtml) file

This file will be one which will hold all the HTML/CSS/SCRIPT needed to render the rating controller. having it one centralized template file makes it very easy for us to make any changes in the way it renders without having to edit multiple place. this file should reside in the folder application/views/scripts.

3. The Model (to interact with the database table)

this file will have all the functions to ADD/REMOVE/GET ratings entered by users. this file can be used to introduce new rules, or different storage mediums later on. the initial view helper file we discussed about will always be talking directly to this model to grab necessary information which it needs to render the rating tool.

4. The controller file (main access point for data submissions)

This file will be used to capture the event of user ratings. so once the user clicks on the rating control the AJAX request will be directed to this controller's add action. and from there it will communicate it with the model to get it saved in the database. this file shud be placed on /application/controllers/ folder.

i will have to find some other way to post code samples into the blog post straight away, but for the time being i cant figure out a way to add the PHP/XHTML code into this blog post. i will re edit this post once i figure out a solution for that.

happy coding!!!

[update Jul2014]
all the source code for this article can be downloaded from here.
Looks like the website that hosted the sample source code is not in use anymore. I will try to find the original source code and post it here.