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 ?
First:
public function indexAction()
{
$this->view->controller = $this
}
In your view script:
<html><title><?php echo $this->controller->getResultByID($this->id); ?></title></html>
By using Action View Helper :
http://framework.zend.com/manual/1.12/en/zend.view.helpers.html#zend.view.helpers.initial.action
If the indexAction
is executed you could call it from there:
public function indexAction()
{
$this->getResultByID( (int) $_REQUEST['id'] );
}
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
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
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.