my problem is the following:
i would like to use a login element instead of a login view.
so i can use the login in my default.ctp… i want the user to have the possibility to login from every page. It should be a sort of dropdown menu.
How can i tell my controller to use the element and get the element data and not the view anymore?
My LoginsController login function:
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');
}
My View/Element:
<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>
I call the element in the default.ctp like this:
<?php echo $this->element('/logins/login'); ?>
Its always complaining about missing the login view…
If this isnt a good practise, please teach me otherwise 😉
Sorry for my bad english and thanks!
Have you tried disabling the view in the controller?
If the element is included in default.ctp, adding
in place of
in your login controller will stop the Login Controller trying to specifically render the view.
You will need to place your element in the Elements directory (under ‘Views’) and then update your code in default.ctp to be
Also, using the cakephp way of setting up the links and forms may help you in the element.
For full guidance for the form, try here: http://book.cakephp.org/2.0/en/core-libraries/helpers/form.html
For how to do links the cake way, try: http://book.cakephp.org/2.0/en/core-libraries/helpers/html.html