简体   繁体   English

CakePHP 2.0中的表单助手出现错误

[英]Error with Form helper in CakePHP 2.0

I'm starting out with CakePHP 2.0 and can't get past a simple login. 我开始使用CakePHP 2.0,无法通过简单的登录。 This is my code: 这是我的代码:

AppController: AppController的:

class AppController extends Controller
{
    function beforeFilter()
    {
        $this->Auth->userModel = 'User';
        $this->Auth->fields = array('username' => 'email', 'password' => 'password'); 
        $this->Auth->loginAction = array('controller' => 'users', 'action' => 'login');
        $this->Auth->loginRedirect = array('controller' => 'hotels', 'action' => 'dashboard');
    }
}

UsersController: UsersController:

class UsersController extends AppController
{
    var $name = 'Users';
    var $helpers = array('Html','Form');
    var $components = array('Auth','Session');

    function beforeFilter()
    {
        $this->Auth->allow("logout");
        parent::beforeFilter();
    }

    function logout()
    {
        $this->redirect($this->Auth->logout());
    }

    function login()
    {
        if ($this->Auth->login())
        {
            $this->redirect($this->Auth->redirect());
        } else
        {
            $this->Session->setFlash(__('Invalid username or password, try again'));
        }
    }
}

login.ctp: login.ctp:

 echo $this->Form->create(); //'User', array('action' => 'login'));
 echo $form->Form->input('email');
 echo $form->Form->input('password');
 echo $form->Form->end('Login');

The error I'm getting is this: 我得到的错误是这样的:

 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

Any ideas? 有任何想法吗? Thanks in advance! 提前致谢!

These 这些

echo $form->Form->input('email');
echo $form->Form->input('password');
echo $form->Form->end('Login');

should be 应该

echo $this->Form->input('email');
echo $this->Form->input('password');
echo $this->Form->end('Login');

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM