0

I'm working on a website using Zend Framework 1 that requires a login to have access and have created a controller name UserController with an action named loginAction to facilitate the logins. Currently, I have the system setup so it redirects the user to /user/login if they attempt to access the site and they aren't logged in but this changes the URL and we doesn't want this to happen. This has brought me to the point where I'm trying to switch the controller inside of the controller if the user hasn't logged in. I have this so far:

require_once(APPLICATION_PATH . '/controllers/UserController.php');
$this->_helper->viewRenderer->renderBySpec('login', array('controller'=>'user'));
$controller = new UserController($this->getRequest(),$this->getResponse());
return $controller->loginAction();

This still renders the page I'm trying to hide but it does appear to be calling the loginAction. Does anyone have a better way to do this or how I can it be fixed?

1 Answer 1

3

You can try to call inside your controllers preDispatch method: _forward().

public function preDispatch()
{
    parent::preDispatch();
    if (!is_user_logged) {
        $this->_forward('login','user');
    }
}

Reference: http://framework.zend.com/manual/1.12/en/zend.controller.action.html#zend.controller.action.utilmethods

Sign up to request clarification or add additional context in comments.

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.