Welcome, Guest. Register Now!
   
Mark Forums Read Mark Forums Read Mark Forums Read


Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 01-16-2008, 02:08 PM
Junior Member
 
Join Date: Jan 2008
Posts: 1
Default Find out controller name BEFORE dispatcher call

Hi,

I'm trying to make a routing decition in my index.php based on some cookie information and on the controller, the visitor will be routed to.

Example: I have a website with "static pages" (staticController) and some "restricted pages" (restrictedController). Further on I have (or not) a cookie telling me, if I can access the restriced pages. Now based on my cookie and the page, the visitor wants to see, I have to decide, where to route him. If he has no cookie and wants to see the restricted page, I will redirect to a special static page. If he has no cookie and wants to see a static page, it's ok. And so on.

I want to know, what controller the router will choose, before the dispatch() of the front controller is being called. Is there a way to do this?
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #2 (permalink)  
Old 01-18-2008, 07:28 AM
Member
 
Join Date: Aug 2007
Location: Sweden
Posts: 52
Send a message via MSN to Leif.Högberg
Default

PHP Code:
<?php
  
/** Zend_Controller_Plugin_Abstract */
require_once 'Zend/Controller/Plugin/Abstract.php';

class 
Foo_Controller_Plugin_MyPlugin extends Zend_Controller_Plugin_Abstract
{
    
/**
     * preDispatch() plugin hook -- 
     *
     * @param  Zend_Controller_Request_Abstract $request
     * @return void
     */
    
public function preDispatch(Zend_Controller_Request_Abstract $request)
    {
         
//the following functions will tell you where the visitor is heading
        
$request->getModuleName();
        
$request->getControllerName();
        
$request->getActionName();

        
//this will send the user elsewhere.
        
$request->setModuleName('modname')
            ->
setControllerName('controllername')
            ->
setActionName('actionname')
            ->
setDispatched(false);
    }
}
Then just register the plugin in your bootstrap
PHP Code:
$controller Zend_Controller_Front::getInstance();
$controller->registerPlugin(new Foo_Controller_Plugin_MyPlugin()); 
And you are ready to rock!
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 04-15-2008, 01:45 AM
Junior Member
 
Join Date: Apr 2008
Location: Canada
Posts: 8
Default

That's almost all that I need myself, I think.

I want to put my Auth & ACL within a single preDispatch, so I don't have to repeat it for all my controllers.

The problem I ran into was how to redirect to the login form when either fails (user isn't logged in or user does not have permission).

Using
Code:
$request->setControllerName('controllername')
appears to mostly work, but...

1. How can I pass a $_GET variable as well (/controller/action?var=something)?

2. How can I have the rest of my preDispatch skipped? Just use
Code:
return;
?
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT. The time now is 07:20 PM.