2010年8月8日星期日

[fw-mvc] View Helper classes - best solution for this scenario?

Hi,

I'm new to the mailing list and not too new to the Zend framework, but pretty basic at it. I am "sort of" making use of the framework as follows:

- I am running my site with controllers and views, (IndexController, index.phtml view) but have not actually incorporated the logic of "models" yet. I know, I need to utlisie the MVC architecture "properly" but the site right now uses a controller and view, and a bunch of "include" files with shared code and functions.

- The requirement is to print a number of Javascript tracking codes on the web pages and this can be easily achieved via  the index.phtml file, as I can create a class or functions to basically print different tags per page depending on certain factors (such as the page itself and the page type). Instead of creating a simple class file, I am contemplating using a "Zend Helper" class - I am new to this, so I was hoping someone could guide me in the right direction. The idea is to centralise the code for this new requirement, to have the code all in one file with functions (i.e. a class file) that I can use in the views/scripts/index.phtml file . For example on the home page I may call the function

printPageTag("home");  //to print a simple JS tag with the page ID "home"

and on the products page I may call the functions

printPageTag("products"); //print JS tag with page ID "products"
printProductTag("general-list");  //print another tag specially for the products page

I was wondering if a "helper" is the right thing for me here (http://framework.zend.com/manual/en/zend.view.helpers.html), or if I should create a class file and just include/instantiate it from my view? What is the recommended approach?

Many thanks,
Rishi


没有评论: