Author Topic: Best way to change controller and action  (Read 554 times)

0 Members and 1 Guest are viewing this topic.

Offline milesapTopic starter

  • Enthusiast
  • Posts: 64
    • View Profile
Best way to change controller and action
« on: August 20, 2009, 12:54:38 PM »
Hello everyone,

I would like to know the best way to approach this problem. I would like my website to check if a user has changed their password within say 4 weeks. If it hasn't been changed, I would like to change the requested controller and action to the change password controller / action.

My question therefore is, where should I put this code? In the bootstrap, register a plugin, or another solution? Also, how could I change the controller and action that is displayed to the user if they are required to change their password? Should they be forwarded to the change password controller / action, or can you change the controller / action after dispatch to the change password controller / action? So if a user was on their profile page, but their password is no longer valid I would like to display the change password form instead of their profile.

I would prefer the website to check if the password has expired for every page request, and not just during login. I know this is less efficient, however in the future I would like to use this same concept to check for other conditions which may change while the user is logged in.

Any help would be much appreciated!

Offline Zyx

  • Enthusiast
  • Posts: 127
  • Gender: Male
    • View Profile
    • Invenzzia open-source group
Re: Best way to change controller and action
« Reply #1 on: August 31, 2009, 05:44:13 AM »
I'd write a plugin and overwrite the dispatchLoopStartup() method:

class My_Controller_Plugin_Password extends Zend_Controller_Plugin_Abstract
{
    public function 
dispatchLoopStartup(Zend_Controller_Request_Abstract $request)
    {
        if(
passwordNeedsToBeChanged())
        {
            
$request->setControllerName('auth');
            
$request->setActionName('password');
        }
    } 
// end dispatchLoopStartup();
// end My_Controller_Plugin_Password;


Note that your plugin does not have to check, if we are in the password change action or not, because dispatchLoopStartup() is not called again after modifying the $request object.
My open-source projects:
Open Power Template - template engine for PHP
TypeFriendly - documentation and user manual builder

Offline thorpe

  • Administrator
  • 'Mind Boggling!'
  • *
  • Posts: 29,255
    • View Profile
Re: Best way to change controller and action
« Reply #2 on: August 31, 2009, 07:43:40 AM »
You might want to mention the framework your using.