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


Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 06-11-2008, 01:41 PM
Junior Member
 
Join Date: Jun 2008
Posts: 2
Default Getting object in all my views

Hello,

I'm just new using the Zend Framework and i'm testing some stuff. At the moment i'm bussy in my bootstrap file where I declare some of my objects, for example a log-object, translate-object, ...

Now I just want to call those object in my *.phtml files. 've read some stuff about the Zend Registry Class and I can use it, so what I do now in my phtml file is (translate object is known in my bootstrap file):
PHP Code:
$translate Zend_Registry::get('translate'); 
But is it possible to call my $translate object straightaway, without using the extra line (zend_registry::get...)? I've read about the Zend_View class, but therefore you have to put the $translate variable to every view, or am I wrong?

Thx
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #2 (permalink)  
Old 06-11-2008, 02:51 PM
Junior Member
 
Join Date: Jun 2008
Posts: 18
Default

No, your always going to have to have that atleast once, either in your controller or your view.
Remember your view scripts are within the scope of the controller, so you could set it in your controller init() to get it and save it to the $-view
but there is NO point at all.

If you do it by reference (which you should) then its just a benefit for not writing the extra line, but if you don't then you are just duplicating the data.
My translation file of 3MB would mean that an extra 6Mb is saved in RAM. Not worth it.

Overall, its not that big of a deal to just add the extra line is it?
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 06-12-2008, 06:18 AM
Junior Member
 
Join Date: Jun 2008
Posts: 2
Default

Thanky you very much for the information, so if i'am correct, i should call this in my controller:
PHP Code:
$translate Zend_Registry::get('translate'); 
And in my controller i can pass it to my view?

For me it's not about typing the extra line, it's just that I would like to optimize my php-code and therefore i asked the question.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #4 (permalink)  
Old 06-12-2008, 09:48 AM
Junior Member
 
Join Date: Mar 2008
Posts: 13
Default

Couldn't You just use PHPTAL :: Template Attribute Language for PHP as view? It's really great project and best thing is that it perfectly cooperate with ZF (You can pass objects directly to template). There is also i18n: PHPTAL
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 11:35 AM.