How to call controller function in view in Zend Framework?

11,820

Solution 1

First:

public function indexAction()
{
  $this->view->controller = $this
}

In your view script:

<html><title><?php echo $this->controller->getResultByID($this->id); ?></title></html>

Solution 2

By using Action View Helper :

http://framework.zend.com/manual/1.12/en/zend.view.helpers.html#zend.view.helpers.initial.action

Share:
11,820
user1745968
Author by

user1745968

Updated on June 04, 2022

Comments

  • user1745968
    user1745968 almost 2 years

    In Zend Framework, I have one controller

    class TestController extends Zend_Controller_Action
    {
    
        public function indexAction()
        {
    
        }
    
        public function getResultByID( $id )
        {
            return $id;
        }
    
    }
    

    How can I call the function getResultByID in index.phtml ?

    • David Weinraub
      David Weinraub over 11 years
      Do you really need to call the getResultByID() in the view? Why not call that method in the controller and pass the result to the view (which would be the more standard approach)?
  • user1745968
    user1745968 over 11 years
    so it's impossible to call the function directly in view?
  • Adarsh Khatri
    Adarsh Khatri about 8 years
    This is the best answer I would say. Why people haven't accepted!
  • Kamlesh
    Kamlesh about 4 years
    zend 3 question: How can we fetch cms pages title and their links to display them in header / footer sections of entire website. Pages title and links are stored in database. Please share any suggestion. Thanks.