2012-07-06 101 views
0

我工作蛋糕2.1.3和routes.php文件文件,一切正常,除了登錄管理帶走蛞蝓,比如我想我的網址如下:登錄從我的網址

http://mysite.com/companyx/users/login

其中公司CompanyX是蛞蝓,但是當您運行網址在瀏覽器如下:

http://mysite.com/users/login

在我定義爲這個文件routes.php文件如下:

Router::connect(
     '/:slug/users/login', // E.g. /companyx/users/login 
     array('controller' => 'users', 'action' => 'login'), array(
     // order matters 
     'pass' => array('slug') 
     ) 
    ); 

與其他控制器我沒有問題,例如:

Router::connect(
     '/:slug/users', // E.g. /companyx/users 
     array('controller' => 'users', 'action' => 'index'), array(
     // order matters 
     'pass' => array('slug') 
     ) 
    ); 

此致)

回答

0

CakePHP有在AuthComponent定義缺省登錄的動作。 (171行)

/** 
    * A URL (defined as a string or array) to the controller action that handles 
    * logins. Defaults to `/users/login` 
    * 
    * @var mixed 
    */ 
public $loginAction = array(
    'controller' => 'users', 
    'action' => 'login', 
    'plugin' => null 
); 

您可以在自己的UsersController中用beforeFilter覆蓋此操作。

0

謝謝你的回答。我以這種方式解決了這種情況:

public function beforeFilter() { 
    parent::beforeFilter(); 
    if (!$this->request->is('post')) { 
     $this->Auth->loginAction = 'this is:slug/users/login/'; 
    } 
} 

「這是slu」「,應該是slu。子。

最好的問候。