i know view helpers. but i think this is expensive and there must be an
other (pre defined) ways. whatever.

thank a lot


2009/4/8 Thomas VEQUAUD <thomas.vequ...@gmail.com>

> You'd better use Zend_View_Helper :
>
> *Just a little example*
> 1. In /application/views/script/helpers/ControllerName.php
> class Zend_View_Helper_ControllerName
> {
>     function controllerName()
>     {
>         // Controller name
>         $fc = Zend_Controller_Front::getInstance();
>         $request = $fc->getRequest();
>         $controllerName = strtolower($request->getControllerName());
>         return ($controllerName);
>     }
> }
>
> 2. Then, you can call this method wherever you want
> in a controller : $this->view->controllerName()
> in a view script : $this->controllerName()
>
>
>
> 2009/4/8 Elvin Şiriyev <el...@siriyev.net>
>
>> another question for layout.
>> for
>> <html xmlns="http://www.w3.org/1999/xhtml";
>> xml:lang="<?=$this->translate->getLocale()?>"
>> lang="<?=$this->translate->getLocale()?>">
>>
>> i solved it like
>> abstract App_Controller_Action extends Zend_Controller_Action {
>>          function init(){
>>                parent::init();
>>                $this->translate = Zend_Registry::get('....');
>>                $this->view->translate = $this->translate;
>>                ...
>>                ..
>>                . (user, acl, navigation etc.)
>>          }
>> }
>> but i didn't like that way.
>>
>> and i need $user object (ex. Zend_DbTable_Row), or Zend_Acl at lot of view
>> scripts
>>
>> PS. sorry for my english.
>>
>>
>> 2009/4/8 keith Pope <mute.p...@googlemail.com>
>>
>>> Accessing from controller is done via $this->getInvokeArg(), if you
>>> use FC parameter.
>>>
>>> You may want to look at why you want to have config, cache and locale
>>> access in your view, generally this would happen in the Model or
>>> controller.
>>>
>>> If you do need to do this I would suggest using a view helper, this
>>> way you encapsulate the access away from the main view scripts.
>>>
>>> class Zend_View_Helper_MyViewHelper
>>> {
>>>    public function MyViewHelper ()
>>>    {
>>>        $fc = Zend_Controller_Front::getInstance();
>>>        $fc->getParam('xxx');
>>>
>>>        // or
>>>         $config = Zend_Registry::get('Zend_Config')
>>>    }
>>> }
>>>
>>> There are of course many ways to do push stuff into views, in your
>>> bootstrap you can set variables on the view, and you can use front
>>> controller plugin, action helpers etc.
>>>
>>> Just have a think to why you need to do this, it may be that this
>>> should be handled in your Model.
>>>
>>> Thx
>>>
>>> Keith
>>>
>>> 2009/4/8 Elvin Şiriyev <el...@siriyev.net>:
>>> > 2. way sounds good. but how can i access frontController's params from
>>> > controller and view script ?
>>> > i dont like write that codes for each Action
>>> > ----------------------------------
>>> > $config = Zend_Registry::get('Zend_Config');
>>> > $cache = Zend_Registry::get('Zend_Cache');
>>> > $locale = Zend_Registry::get('Zend_Locale');
>>> > ..
>>> > .
>>> > $this->view->config  = $config;
>>> > $this->view->cache = $cache;
>>> > $this->view->locale = $locale;
>>> > ..
>>> > .
>>> > ---------------------------------
>>> > 2009/4/8 keith Pope <mute.p...@googlemail.com>
>>> >>
>>> >> Maybe use the registry for that, so have a bootstrap class resource
>>> >> that fetches the plugin resources:
>>> >>
>>> >> protected _initRegistry()
>>> >> {
>>> >>    $this->bootstrap('db');
>>> >>    Zend_Registry::set('dbResource', $this->getPluginResource('db'));
>>> >> }
>>> >>
>>> >> Or you could pass them as params to the front controller, which would
>>> >> make them accessible inside controllers:
>>> >>
>>> >> protected _initFrontControllerExtras()
>>> >> {
>>> >>    $this->bootstrap('frontcontroller');
>>> >>    $this->frontController->setParam('x','xxx');
>>> >>    // or
>>> >>
>>> >>
>>>  
>>> $this->getPluginResource('frontController')->getFrontController()->setParam('x','xxx');
>>> >> }
>>> >>
>>> >> Hope this helps
>>> >>
>>> >> Keith
>>> >>
>>> >> 2009/4/8 Elvin Şiriyev <el...@siriyev.net>:
>>> >> > hi, i used Zend_Application with Zend_Application_Resource_*.
>>> >> > how can i access to that objects from my Controller and view?
>>> >> >
>>> >> > for example is there any way to access Zend_Application_Resource_
>>> >> > Navigation 's  getContainer() method from controller like
>>> >> > $this->navigation->getContainer() or $this->db, $this->layout,
>>> >> > $this->locale
>>> >> > or another easy way ?
>>> >> >
>>> >> > thanks
>>> >> >
>>> >> > --
>>> >> > Elvin Şiriyev
>>> >> > http://elvin.siriyev.net
>>> >> >
>>> >> > --
>>> >> > Elvin Şiriyev
>>> >> > http://elvin.siriyev.net
>>> >> >
>>> >>
>>> >>
>>> >>
>>> >> --
>>> >> ----------------------------------------------------------------------
>>> >> [MuTe]
>>> >> ----------------------------------------------------------------------
>>> >
>>> >
>>> >
>>> > --
>>> > Elvin Şiriyev
>>> > http://elvin.siriyev.net
>>> >
>>>
>>>
>>>
>>> --
>>> ----------------------------------------------------------------------
>>> [MuTe]
>>> ----------------------------------------------------------------------
>>>
>>
>>
>>
>> --
>> Elvin Şiriyev
>> http://elvin.siriyev.net
>>
>
>
>
> --
> Thomas VEQUAUD          http://thomas.vequaud.free.fr/
> Expert EPITECH en Ingénierie Informatique
> Tél : +33(0)6.50.39.28.10  Fax: +33(0)9.58.46.10.07
>



-- 
Elvin Şiriyev
http://elvin.siriyev.net

Reply via email to