Warnin:非法的偏移类型[CORE \Cake\Model\Model.php,line 2734]点击登录PHP [英] Warnin:Illegal offset type [CORE\Cake\Model\Model.php, line 2734] came on click of login in PHP

查看:311
本文介绍了Warnin:非法的偏移类型[CORE \Cake\Model\Model.php,line 2734]点击登录PHP的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用Cake Php.创建了一个简单的登录表单。当我点击登录按钮一个警告出现

I created a simple login form using Cake Php.When i click on the Login button one Warning appear

Illegal offset type [CORE\Cake\Model\Model.php, line 2734

我使用链接参考 http:/ /bakery.cakephp.org/articles/SeanCallan/2007/04/17/simple-form-authentication-in-1-2-xx

代码of Login.ctp

Code of Login.ctp

<?php echo $this->Form->create('User', array('action' => 'login'));?>
    <?php echo $this->Form->input('username');?>
    <?php echo $this->Form->input('password');?>
    <?php echo $this->Form->submit('Login');?>
<?php echo $this->Form->end(); ?>


2.模式文件

2. modal file

3.controller文件

3.controller file

<?php 
App::uses('AppController', 'Controller');
class UsersController extends AppController
{
    var $name = "Users";
    var $helpers = array('Html', 'Form');
      var $components = array("Auth"); 
    function index()
    {

    }

    function beforeFilter()
    {
        $this->__validateLoginStatus();
    }

    function login()
    {
        if(empty($this->data) == false)
        {
            if(($user = $this->User->validateLogin($this->data['User'])) == true)
            {
                $this->Session->write('User', $user);
                $this->Session->setFlash('You\'ve successfully logged in.');
                $this->redirect('index');
                exit();
            }
            else
            {
                $this->Session->setFlash('Sorry, the information you\'ve entered is incorrect.');
                exit();
            }
        }
    }

    function logout()
    {
        $this->Session->destroy('user');
        $this->Session->setFlash('You\'ve successfully logged out.');
        $this->redirect('login');
    }

    function __validateLoginStatus()
    {
        if($this->action != 'login' && $this->action != 'logout')
        {
            if($this->Session->check('User') == false)
            {
                $this->redirect('login');
                $this->Session->setFlash('The URL you\'ve followed requires you login.');
            }
        }
    }

}

?>

为什么会发生这种情况。一些开发人员在PHP聊天室建议我不要使用那蛋糕PHP。任何帮助

Why that happened.i am new in this.Some developers in PHP chat room suggest me to not use that Cake PHP. Any help is appreciated

推荐答案

非法偏移类型意味着您尝试使用对象或数组来索引数组: p>

Illegal offset type means that you tried to use an object or an array to index an array:

$x = stdClass;
$a = array(1,2,3,4);
$a[$x]; // illegal offset type

检查您的代码中可能存在用户输入的地方是一个值的数组,即使你认为它只是一个值),并在一些函数中使用它只预期一个值。

Check your code for possible places where you've taken user input (which could be an array of values even though you thought it's just one value) and used it in some function that expected just a value.

如果Cake内部函数期望一个值,尝试使用它作为数组的偏移量,将出现此消息。

If that Cake internal function expected a value and tried to use it as the offset of an array, this message would appear.

我注意到你的代码中传递参数(而不是文字字符串值)在这里:

The only place I notice in your code that passes a parameter (and not literal string values) is here:

$this->User->validateLogin($this->data['User']))

> data ['User'] ['id']我在这里提供了一个数组,它可以是一个数组,你应该已经提取了$ this-> data ['User'] ['id'] $ don-> var_dump 不知道,我没有玩Cake。

Do a var_dump on $this->data['User'] and see what's in it perhaps it's an array and you should've extracted just $this->data['User']['id'] I don't know, i haven't played that much with Cake.

这篇关于Warnin:非法的偏移类型[CORE \Cake\Model\Model.php,line 2734]点击登录PHP的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆