2
<?php
 class PI_Controller_Plugin_AssetGrabber extends Zend_Controller_Plugin_Abstract
{
public function dispatchLoopStartup(Zend_Controller_Request_Abstract $request)
{
    /*
        The module name
    */
    $moduleName = $request->getModuleName();
    /*
        This modules requires the user to be loggedin in order to see the web pages!
    */
    $loginRequiredModules = array('admin');

    if (in_array($moduleName,$loginRequiredModules)) {
        $adminLogin = new Zend_Session_Namespace('adminLogin');
        if (!isset($adminLogin->loggedin)) {
            /*--------------------------------------
               Here I want to redirect the user
            */
             $this->_redirect('/something');
        }
    }   
}
}

I'm trying to do a redirect $this->_redirect('/something') but doesn't work! Do you know how can I do a redirect in this case?

Best Regards,

2
  • What's the error message? Nothing? Simply don't redirect? You could try $this->_helper->redirector() too, or $this->_helper->gotoUrl() see more on framework.zend.com/manual/en/…. Commented Mar 12, 2010 at 14:09
  • I can't use those things in my plugin, because you can ONLY use $this->_redirect ..only if you extend the Zend_Controller_Action Commented Mar 12, 2010 at 14:56

3 Answers 3

7

... rest of code

if (!isset($adminLogin->loggedin)) {
    $baseUrl = new Zend_View_Helper_BaseUrl();
    $this->getResponse()->setRedirect($baseUrl->baseUrl().'/something');
}

... rest of code

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

Comments

5
<?php
class AlternativeController extends Zend_Controller_Action
{
    /**
     * Redirector - defined for code completion
     *
     * @var Zend_Controller_Action_Helper_Redirector
     */
    protected $_redirector = null;

    public function init()
    {
        $this->_redirector = $this->_helper->getHelper('Redirector');
    }

    public function myAction()
    {
        /* Some Awesome Code */

        $this->redirector('targetAction', 'targetController');
        return; //Never reached!
    }
}

You need to get the redirector helper, then you can define the targetAction and targetController with the redirector. That should do it.

4 Comments

In your code you can use $this->_redirect but If you look at my code you will see that I'm wrting an Asset Plugin Controller.
Uffo you still need to get the helper regardless. You can also use $this->_redirector->gotoUrl('/my-controller/my-action/param1/test/param2/test2');
I don't get it, why I have to create a controller in order to use an helper, I want to use that helper in my plugin, not in my controller.
The controller was the example I gave, the method is identical for other purposes. Just go read the Framework manual at this point.
2

Either use Zend_Controller_Action_HelperBroker to get the redirect helper or do the redirect directly from the Request object.

See the examples given in

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.