Welcome, Guest. Register Now!
   
Mark Forums Read Mark Forums Read Mark Forums Read


Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 05-21-2008, 02:55 PM
Junior Member
 
Join Date: May 2008
Posts: 4
Default Getters and Setters?

Hi there!

I've been working with PHP-OO and Java for the last two years and some days ago I decided to work with Zend in a new project.

The problem I've appears when I want to access to a variable in a controller but from another controller. I've tried implementing getters but this doesn't work, I think due to the Zend (MVC) architecture ...

Could somebody teach me in the right way please? There is either a specific form to use getters/setters or I should use another Zend method?

Thanks!
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #2 (permalink)  
Old 05-21-2008, 05:54 PM
Junior Member
 
Join Date: Mar 2008
Posts: 26
Default

why would you you variable from another controller? it is agiansts the whole MVC nature, I suppose. give as some detail example, please
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 06-03-2008, 12:03 PM
Junior Member
 
Join Date: May 2008
Posts: 4
Arrow

A simple example could be the next one:

You have some information in a DB that you want to read from a controller. Then you generate some code with this and give it to the view. Here is no problem except when you have 2 other controllers that need the same generated code (just to avoid the code duplication, ok?).

So, what if I want to do the same I could do with Java or PHP5 ("ZFless")?

Thanks in advance!
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #4 (permalink)  
Old 06-04-2008, 05:40 AM
Junior Member
 
Join Date: Jun 2008
Posts: 18
Default

Im also relatively new to the MVC architecture since I have developed all my applications as a single project I have never needed to.
However, isn't the whole idea behind MVC that you only have a single controller. (Please do correct me if I am wrong, I would hate to misdirect people and would like to be corrected).
You should never have more then one controller.

The controller should handle the users request to decide what to do. It handles the initial logic. The way I think of it is just to figure out what page the user wants it directs the user along the right path.
Once you know what page you want, you can use the model to grab any information from the database and then the controller can handle the logic again and pass on the load to the view.

You shouldn't do reading in a database from controllers if you are going to output it. You can do logic reading I GUESS?? (correct me) ie if you are checking which site to load (if your database contains 1000s of sites (like bebo??)).

Let me know if this is the correct approach.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #5 (permalink)  
Old 06-04-2008, 10:26 AM
Junior Member
 
Join Date: May 2008
Posts: 4
Default

Thanks for your contribution Kalyse.

The idea of having just one controller is good when you have little site (or even huge if you feel comfortable with it) but I think the "good way" goes through having different controllers (i.e.: AdminController, ContentController, ErrorController, ...). So what you said is ok but does not answer my question.

Thanks.

Somebody else with any idea???
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #6 (permalink)  
Old 06-04-2008, 06:14 PM
Junior Member
 
Join Date: Mar 2008
Posts: 26
Default

i think that Kalyse is misunderstanding some things. There should be one, but frontcontroller :P

Next, if you want to do the same in several controllers, try to extend model (e. include getMenu() method which return entire menu in form of array, instead of doing this logic in controller).
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #7 (permalink)  
Old 06-10-2008, 06:26 AM
Junior Member
 
Join Date: Jun 2008
Posts: 18
Default

Quote:
Originally Posted by kuba View Post
i think that Kalyse is misunderstanding some things. There should be one, but frontcontroller :P

Next, if you want to do the same in several controllers, try to extend model (e. include getMenu() method which return entire menu in form of array, instead of doing this logic in controller).
Yes I did. After fully reading the docs I see my post couldn't have been futher from the truth.
You should wholly disregard it as total bs.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #8 (permalink)  
Old 06-10-2008, 06:28 AM
Junior Member
 
Join Date: Jun 2008
Posts: 18
Default

I think what you want to do is either:

User

Zend_Registry -

Or you could use

$this->getRequest->setParam('myparameter') = 'value';

You could then access it in your other conroller using

$this->getRequest->getParam('myparamterer') //ignore the type.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #9 (permalink)  
Old 06-10-2008, 02:07 PM
Member
 
Join Date: Aug 2007
Location: Sweden
Posts: 52
Send a message via MSN to Leif.Högberg
Default

"You have some information in a DB that you want to read from a controller. Then you generate some code with this and give it to the view. Here is no problem except when you have 2 other controllers that need the same generated code (just to avoid the code duplication, ok?)."

Based on the above example I would say that you need to create an action helper. This helper could then be reused in your other controllers.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT. The time now is 05:14 AM.