Your browser (Internet Explorer 6) is out of date. It has known security flaws and may not display all features of this and other websites. Learn how to update your browser.
X

[SOLVED] Call to undefined method PhalconMvcViewSimple::disable() - Phalcon 2.0.0

There is a little bug in Phalcon 2.0.0, trying to reference a method that does not exist again in View class. This method existed in version 1.3.4 but somehow was removed.


let dependencyInjector = this->getDI();

if !header {
let url =  dependencyInjector->getShared("url"),
header = url->get(location);
}

if dependencyInjector->has("view") {
let view =  dependencyInjector->getShared("view");
view->disable();
}

Whoever has removed the method obviously did not consider that there is a call to it when redirect is called if the view is passed to DI(Dependency Injection). If this is not considered a bug then Phalcon team has decided that we shouldn't inject the view into our application if we would ever call "return $this->response->redirect()". The call to redirect checks if you injected a view and trys to call disable view. This throws an error because there is no more method called disable in View class for Phalcon 2.0.0.

Here is how to resolve this problem. Remove the view you injected via the services script (services.php). Go to your ControllerBase.php and add your view as you would use it normally.


use Phalcon\Mvc\Controller,
Phalcon\Mvc\Dispatcher,
Phalcon\Mvc\View\Simple as SimpleView,

class ControllerBase extends Controller
{
public $view;
protected $di;

public function initialize()
{
$this->di = $this->getDI();

$this->view = new SimpleView();
$this->view->setViewsDir($this->di->get('config')->application->viewsDir); //this is to set your view directory
}

public function afterExecuteRoute()
{ 
$this->view->setViewsDir($this->view->getViewsDir() . 'admin/');
}

/**
* Execute before the router so we can determine if this is a provate controller, and must be authenticated, or a
* public controller that is open to all.
*
* @param Dispatcher $dispatcher
* @return boolean
*/
public function beforeExecuteRoute(Dispatcher $dispatcher)
{

}
}

You can then use $this->view in your controllers.


class AccountsController extends ControllerBase
{ 
public function loginAction()
{
$config = $this->di->get('config'); 

$config->api->google->state = $this->session->getId();
$this->view->setVar('googleLogin', $config->api->google);

$this->view->setVar( "title", "Account Login" );

echo $this->view->render('admin/login');

}

What we have done is to bypass the check that trys to call method disable() that was not implemented in the class View and being called when calling the redirect method.

Hope this makes you happy. :-)

 


comments powered by Disqus