Note that there are some explanatory texts on larger screens.

plurals
  1. POError with Form helper in CakePHP 2.0
    text
    copied!<p>I'm starting out with CakePHP 2.0 and can't get past a simple login. This is my code:</p> <p><strong>AppController:</strong></p> <pre><code>class AppController extends Controller { function beforeFilter() { $this-&gt;Auth-&gt;userModel = 'User'; $this-&gt;Auth-&gt;fields = array('username' =&gt; 'email', 'password' =&gt; 'password'); $this-&gt;Auth-&gt;loginAction = array('controller' =&gt; 'users', 'action' =&gt; 'login'); $this-&gt;Auth-&gt;loginRedirect = array('controller' =&gt; 'hotels', 'action' =&gt; 'dashboard'); } } </code></pre> <p><strong>UsersController:</strong></p> <pre><code>class UsersController extends AppController { var $name = 'Users'; var $helpers = array('Html','Form'); var $components = array('Auth','Session'); function beforeFilter() { $this-&gt;Auth-&gt;allow("logout"); parent::beforeFilter(); } function logout() { $this-&gt;redirect($this-&gt;Auth-&gt;logout()); } function login() { if ($this-&gt;Auth-&gt;login()) { $this-&gt;redirect($this-&gt;Auth-&gt;redirect()); } else { $this-&gt;Session-&gt;setFlash(__('Invalid username or password, try again')); } } } </code></pre> <p><strong>login.ctp:</strong></p> <pre><code> echo $this-&gt;Form-&gt;create(); //'User', array('action' =&gt; 'login')); echo $form-&gt;Form-&gt;input('email'); echo $form-&gt;Form-&gt;input('password'); echo $form-&gt;Form-&gt;end('Login'); </code></pre> <p>The error I'm getting is this:</p> <pre><code> Notice (8): Undefined variable: form [APP\View\Users\login.ctp, line 13] Notice (8): Trying to get property of non-object [APP\View\Users\login.ctp, line 13] Fatal error: Call to a member function input() on a non-object in E:\proyectos\web\swt\app\View\Users\login.ctp on line 13 </code></pre> <p>Any ideas? Thanks in advance!</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload