Reputation: 172
I am trying to redirect the page if condition is true I dont want to use core php function header() because I am using zend so, I have tried many things but in vain.
Here is my code.
$viewer = Engine_Api::_()->user()->getViewer();
$table = Engine_Api::_()->getItemTable('sitebusiness_business');
$select = $table->select()->where('owner_id = ?' , $viewer->getIdentity());
$result = $table->fetchAll($select);
if(count($result) == 0){
$url = Zend_Controller_Front::getInstance()->getRouter()->assemble(array('action' => 'package'), 'sitebusiness_general', true); // url is /mysite/businessitems/package
$this->_redirect($url); //Not Working ----
$this->_helper->redirector($url); //Not Working ----
$this->_redirector->gotoSimple($url); //Not Working ----
$this->_redirector->gotoUrl($url); //Not Working ----
}
Everytime I get the message: Fatal error: Call to a member function redirector() [whatever the function name is] on a non-object.
Thanks in advance.
Upvotes: 1
Views: 61
Reputation: 206
you can use the following one to redirect in zf2
$this->redirect()->toRoute('routename');
Generaly route name is the function name in the controller.
like addEmployeeAction(), editEmployeeAction()...
which is routes defined in module.config.php
'zfcadmin' => array(
'type' => 'segment',
'options' => array(
'route' => '/admin',
'defaults' => array(
'controller' => 'ZfcAdmin\Controller\AdminController',
'action' => 'index',
),
),
'may_terminate' => true,
Upvotes: 1