Jump to content

More generic MVC questions...in ZF


ajlisowski

Recommended Posts

So, I am still struggling to really nail down good design patterns for larger projects. Right now I am trying to convert a project management system I wrote to MVC using ZF.

 

The question is this:

 

I have a project object which can contain many tasks and milestone objects. All of these can contain discussions, documents, members etc.

 

The way I would normally write the code (and did in the original version) is to have each of these elements be their own class. And then have a project->draw function which would cycle through and draw the various parts of the projects. Most other elements would have both a draw() function and a draw_as_child() function.

 

In ZF I have made a project controller with an index action which would handle the viewing of a specific project. I have made a project_obj model as well as a project_db model.

 

project_db handles all the database specific stuff for the project. Project_obj basically handles everything else and acts as an intermediate between the controller and project_db. So in my controller I would simply call project_obj->load(id) and it would load all the data in, and then I could do stuff like project_obj->get_members() etc.

 

So far, I feel confident Im doing things well, but my issue is when it comes to drawing. To me it makes the most sense to do what I did in the old version which is to have draw() and draw_as_child() functions for my various models, but it seems like this would violate MVC as I should likely do all html formatting and what not within the view. However it seems redundent to me not to have a function which simply draws a task as a child since both Projects and Milestons will be using this. On a similar note, discussions, documents, members etc will all be displayed the same in various different areas. What is the best way for me to handle this in MVC?

 

Would I create a task controller with a view_as_child action, and then simply use an action view helper to display the child where needed? Is that how MVC would handle such situations? And do the same with members, documents, discussions, milestones etc?

Link to comment
Share on other sites

but it seems like this would violate MVC as I should likely do all html formatting and what not within the view.

 

Reverse your thinking, create a view helper pass the appropriate models they will do the actual rendering.

 

A model is free of displaying itself and storing itself
Link to comment
Share on other sites

So should I create a view helper for each object? Like a project_view_helper, a task_view_helper, milestone_view_helper, etc?

 

I already plan on having controllers for most of those things, so would my idea of giving those controllers an display_as_child action and then using action_view_helpers to display them from the parent controllers work well within the MVC framework? Or should I make view_helpers for each?

 

I feel like im close to finally clicking with MVC, which would be nice...

Link to comment
Share on other sites

I figure view_helpers would be the best way. I am having a bit of trouble with them using modules.

 

For example, I have a projectplan module, and inside it, one of my views is trying to use a img view helper.

 

I have a class in applications/views/helpers/img.php that is named Zend_View_Helper_Img. When I call it in my view I simply call $this->img() (the view_helper_img class has a function img())

 

I get the following error

 

Exception information:

 

Message: Plugin by name 'Img' was not found in the registry; used paths: Projectplan_View_Helper_: /var/www/html/appldev/luna/application/modules/projectplan/views/helpers/ Zend_View_Helper_: Zend/View/Helper/

 

I tried putting the helper in the applications/modules/projectplan/views/helpers directory but that did not work either. I would like it to be in the default module so all modules can use it, but I am unsure of what I am doing wrong. Any ideas?

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.