I want to set the value of a view-variable (a) a variable that is already
defined under controller's view object (2) assigning new variable to view
object, in my custom helper, as follows;

        public function formAssembly()
        {
                $this->view->title      = "This is Form Assembly"; // title is 
already set in
controller
                $this->view->ahmed      = "World is helloed"; // new variable 
in the helper

        }

While in my view (.phtml) file I am calling the helper as;
$this->formAssembly()

And in my controller;

        public function createAction()
        {
                $this->view->title      = "Create Form";
                
$this->view->addHelperPath("../../views/helpers","FormAssembly");

        }

But 
(1) the title is not getting overwritten when displayed. Seems like _title_
under controller is getting preference or the output is being rendered
before the helper call

(2) the new variable _ahmed_ is not being used in the view file. Seems like
view object is not being passed as reference

Any help?



Matthew Weier O'Phinney-3 wrote:
> 
> -- Cristian Bichis <[EMAIL PROTECTED]> wrote
> (on Tuesday, 10 April 2007, 11:30 AM +0200):
>> I started making my own helpers and since tend to be complex due to
>> interfering
>> with other components
>> 
>> Problem 1:
>> 
>> The helper needs access to some global variables. I added a constructor
>> for
>> that helper:
>> 
>>     public function __construct()
>>     {   
>>         $this->config = Zend_Registry::get('config');
>>     }
>> 
>> I am wondering if this is the best approach... May sound as a stupid
>> question
>> but i am just wondering if same global variables can't be taken from View
>> level
>> or something...
>> 
>> Problem 2:
>> I am creating some custom helpers and one of the helper (A) is using
>> other
>> helper (B).
>> 
>> I can't call him through $this (since this would fail, because $this
>> would
>> reffer to helper class not view class).
>> 
>> The only ways i can think of is by instantiating helper B inside of
>> helper A.
>> Which seems crappy somehow...
>> 
>> Any more effective idea ?
> 
> Yep. In the last release, 0.9.2, we added support to optionally set the
> view object in the helper. All you need to do is add an accessor to your
> helper. As an example, if you have helper 'foo', and want it to access
> helper 'bar':
> 
>     class My_Helper_Foo
>     {
>         public $view;
> 
>         public function setView(Zend_View_Interface $view)
>         {
>             $this->view = $view;
>         }
> 
>         public function foo()
>         {
>             // Need access to helper 'bar':
>             $tmp = $this->view->bar();
> 
>             // Need access to a variable set in the view:
>             $baz = $this->view->baz;
>         }
>     }
> 
> Hope that helps answer your question!
> 
> -- 
> Matthew Weier O'Phinney
> PHP Developer            | [EMAIL PROTECTED]
> Zend - The PHP Company   | http://www.zend.com/
> 
> 

-- 
View this message in context: 
http://www.nabble.com/View-Helper-questions-tf3551748s16154.html#a11596354
Sent from the Zend Framework mailing list archive at Nabble.com.

Reply via email to