CakePHP验证控制器名称 [英] CakePHP auth controllername
问题描述
我有以下Auth组件:
I have the following Auth Component:
public $components = array(
'Auth' => array(
'loginAction' => array(
'controller' => 'Veranstalter',
'action' => 'login',
),
'authenticate' => array(
'Form' => array(
'userModel' => 'Veranstalter',
'fields' => array(
'ID' => 'ID', //Default is 'username' in the userModel
'Password' => 'Passwort' //Default is 'password' in the userModel
)
)
)
)
);
如你所见,我想使用我的ControllerVeranstalter英语单词)
As you can see, I want to use my Controller "Veranstalter" (I HAVE to use non-english words)
当我要登录时,
无法找到Controller Veranstalter s 控制器。
When I want to Login, The Controller VeranstaltersController couldn't be found.
如何解决这个问题?
我的表单看起来像这样: / p>
My Form Looks like this:
<h2>
Login
</h2>
<?php
echo $this->Form->create('Veranstalter', array('action' => 'login'));
?>
<table class="input">
<colgroup>
<col width="15">
<col width="75">
</colgroup>
<tr>
<th>
Veranstalter Nummer
</th>
<td>
<?php echo $this->Form->input('ID',array('type'=>'text','label'=>false)); ?>
</td>
</tr>
<tr>
<th>
Passwort
<td>
<?php echo $this->Form->input('Passwort',array('label'=>false)); ?>
</td>
</tr>
<tr>
<th>
Login
</th>
<th>
<?php echo $this->Form->end('Login');?>
</th>
</tr>
</table>
推荐答案
网址不正确
auth组件使用 loginAction
配置变量与配置完全一致:
protected function _unauthenticated(Controller $controller) {
...
$controller->redirect($this->loginAction);
因此,如果你正在查看的url不是Auth组件配置中的url,不负责。
Logically therefore, if the url you are looking at is not the url in the Auth component config, it is not responsible.
登录表单的代码:
echo $this->Form->create('Veranstalter', array('action' => 'login'));
将生成此标记:
<form ... action="/veranstalters/login">
^
因为这就是Form :: create的工作原理。第一个参数是模型的名称,如果选项中没有指定url,将模型名称转换为知道控制器的名称。
Because that's how Form::create works. The first parameter is the name of a model, and if no url is specified in the options, the model name is inflected to know the name of the controller.
最简单的解决方案是在选项中指定url:
The simplest solution is therefore to specify the url in the form options:
echo $this->Form->create('Veranstalter', array('url' => '/veranstalter/login'));
这将产生正确的网址:
<form ... action="/veranstalter/login">
^
这篇关于CakePHP验证控制器名称的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!