1

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 ?

1
  • 1
    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)? Commented Oct 19, 2012 at 21:16

6 Answers 6

6

First:

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

In your view script:

<html><title><?php echo $this->controller->getResultByID($this->id); ?></title></html>
Sign up to request clarification or add additional context in comments.

2 Comments

This is the best answer I would say. Why people haven't accepted!
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.
1

By using Action View Helper :

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

Comments

0

If the indexAction is executed you could call it from there:

public function indexAction()
{
    $this->getResultByID( (int) $_REQUEST['id'] );
}

1 Comment

so it's impossible to call the function directly in view?
0
  public function getResultByID( $id )
  {
               return $id;
  }

instead of the above code u can use

  public function getResultByID( $id )
    {
         this->view->id=$id;
         this->render('index.phtml');
     }

then you can use the value of id in index.phtl as this->id

Comments

0

Try this code I think this is best choice

public function indexAction()
    {
       $this->view->assign('id' => $this->getResultByID($this->_request->getParam('id', null)))
    }

    public function getResultByID( $id = null )
    {
        return $id;
    }

And in view: echo $this->id

Comments

0

In your indexAction method, return the getResultByID method in an array.

Controller:

public function indexAction()
{
    return array(
       'getResult' => $this->getResultByID($id),
    );
}

public function getResultByID($id)
{
    return $id;
}

The question is where will you get the $id. Anyway, call the getResult string in a variable like this.

View:

echo $getResult;

And that's it.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.