我的问题如下:
我想使用登录元素而不是登录视图。 所以我可以在default.ctp中使用登录...我希望用户可以从每个页面登录。它应该是一种下拉菜单。
我如何告诉我的控制器使用该元素并获取元素数据而不再是视图?
我的LoginsController登录功能:
function login()
{
$this->set('headline','Melden Sie sich an...');
if($this->request->is('post'))
{
if($this->Auth->login())
{
//$this->redirect($this->Auth->redirect);
$this->redirect(array('action' => 'index'));
$this->Session->setFlash('Ihr Login war erfolgreich!');
}
else
{
// $this->Session->setFlash('Ihre Email/Passwort ist falsch!' . ' ' . $this->request->data['Login']['email'] . ' ' . $this->request->data['Login']['password']);
$this->Session->setFlash('Ihre Email/Passwort ist falsch!');
}
}
$this->render('logins/login');
}
我的观点/元素:
<aside id="left">
<div class="whitebox einloggen">
<div class="rahmen">
<h2>Login</h2>
<div class="inside">
<?php echo $this->Html->para(null,'Sind Sie bereits als Nutzer registriert?');
echo $this->Form->create('Login', array('action' => 'login'));
echo $this->Form->input('email', array ('label' => false, 'type'=>'text','class'=>'text', 'value'=>'E-Mail','id'=>'LoginEmail', 'onfocus'=>"resetinput(this);", 'onBlur'=>"fillinput(this);"));
echo $this->Form->input('password', array ('label' => false, 'type'=>'text','class'=>'text', 'value'=>'Passwort','id'=>'LoginPassword', 'onfocus'=>"resetinputpw(this);", 'onBlur'=>"fillinput(this);"));
echo $this->Form->end(array('label'=>'Einloggen','class' => 'button long','type' => 'submit','name'=>'submit'));
echo $this->Html->para('forgetpw', $this->Html->link('Passwort vergessen?', array('controller' => 'login', 'action' => 'forgotpwd'), array('label' => false, 'class' => 'forgetpw', 'title'=>'Passwort vergessen')));
echo $this->Html->link('', array('controller' => 'login', 'action' => 'fblogin'), array('class' => 'facebook-button', 'title'=>'Mit Facebook einloggen'));
?>
</div>
</div>
</div>
我像这样调用default.ctp中的元素:
<?php echo $this->element('/logins/login'); ?>
它总是抱怨错过登录视图......
如果这不是一个好习惯,请另外教我; - )
抱歉我的英文不好,谢谢!
答案 0 :(得分:0)
您是否尝试过禁用控制器中的视图?
如果该元素包含在default.ctp中,则添加
$this->autoRender = false;
取代
$this->render('logins/login');
登录控制器中的将阻止登录控制器尝试专门呈现视图。
您需要将元素放在Elements目录中(在“Views”下),然后将default.ctp中的代码更新为
<?php echo $this->element('login'); ?>
此外,使用cakephp设置链接和表单的方式可以帮助您进行元素。
有关表单的完整指导,请尝试此处:http://book.cakephp.org/2.0/en/core-libraries/helpers/form.html
如何以蛋糕的方式进行链接,请尝试:http://book.cakephp.org/2.0/en/core-libraries/helpers/html.html