I'm trying to implement routes into my bootstrap file with this code ;
protected function _initRoutes()
{
$router = $this->getResource('frontController')->getRouter();
$router->addRoute(
'profil',
new Zend_Controller_Router_Route
(
'profil/:username',
array
(
'controller' => 'users',
'action' => 'profil'
)
)
);
}
but it doesn't work since I get 'Call to a member function getRouter() on a non-object in...' error.
How can I get the controller from bootstrap ?
I believe that your problem is that where you are calling
$this->getResource('frontController')->getRouter()
the FrontController resource has not yet been initialized.
I called the same method in this fashion (which won't work in Zend Framework 2.0 but works for now):
Zend_Controller_Front::getInstance()->getRouter();
Alternatively you can make certain that your front controller is initialized like this:
$this->bootstrap('FrontController');
$front = $this->getResource('FrontController');
You could try:
$front = Zend_Controller_Front::getInstance();
$router = $front->getRouter();
And if you run into any issues these are most likely your culprits:
require_once 'Zend/Controller/Front.php';
require_once 'Zend/Controller/Router/Route.php';
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With