0
votes

I'm trying to get started with Zend Framework , followed the quickstart project and am trying to start a new module of my own. Am trying to implement view helpers and I keep getting the following message: Message: Method formDate does not exist

Last entry at the stack trace:

0 D:\work\quickstart_zend\application\views\scripts\users\register.phtml(38): Zend_Form_Element->__call('formDate', Array)

I have the following file structure:


    quickstart_zend
     + application
        + configs
        + controllers
        [...]
        + views
          + helpers
          + scripts
    
     [...]
     + library
        + Application
          + Form
            + Element
                Date.php
          + View
            + Helper
                FormDate.php
     + public

I have added in my public/Bootstrap.php this method:

    

    protected function _initActionHelpers()
        {
            Zend_Controller_Action_HelperBroker::addPath(APPLICATION_PATH.'/../library/Application/View/Helper', 'Application_View_Helper');
            Zend_Controller_Action_HelperBroker::addPrefix('Application_View_Helper');
        }

I have also added in my application.ini:


    autoloaderNamespaces[] = "Application"
    resources.view.helperPath.Application_View_Helper = APPLICATION_PATH "/../library/Application/View/Helper/"

And i have seen a version and also have tried with resources.view.helperPath.Application_View_Helper_, nothing seems to get it to work.

Of course, i have a Users.php form where i create a 'date' element:


    // Add a dateOfBirth element
    $element = new Application_Form_Element_Date('dateOfBirth');
    $this->addElement($element);

Of course, i have a Users.php form where i create a 'date' element:


    // Add a dateOfBirth element
    $element = new Application_Form_Element_Date('dateOfBirth');
    $this->addElement($element);

And in my view script, where the errors shows up:


    <? echo $form->dateOfBirth->formDate() ?>

What am i missing to get it to work? :-( i've spent a day so far looking for solutions

2
To call view helpers, you should call the method on a view ($instanceOfZendView->formDate()), but you are calling it on a Zend_Form_Element_Date. So no go like this.bububaba
thanks, i now get it, this is it!devplayer

2 Answers

0
votes

to properly use your view helper on that data you would use it like:

In your view (.phtml)

//a view helper should act on a piece of data and return something
//so I assume your formDate() helper takes a date value and reformats it.
<?php echo $this->formDate($this->form->dateOfBirth) ?>

assuming you assigned your form to the view in your controller using the standard:

$this->view->form = $form;
1
votes

You are receiving this error because there is no such method in Zend_Form_Element. I think you are trying to use your view helper to display in some way this form element, but if this is the case it is better to use form decorators. You can use the standard decorators or you can create a custom one. Check the documentation for more info - http://framework.zend.com/manual/en/zend.form.decorators.html