0

次の警告があります

警告(2):不正なオフセットタイプ[CORE / Cake / Model / Model.php、2667行目]

警告(2):不正なオフセットタイプ[CORE / Cake / Model / Model.php、行2643]

モデルコードは次のとおりです。

`<?
class Register extends AppModel
{
    var $name = 'Register';
    var $useTable = 'registers';
function validateLogin($data)
    {
        $user = $this->find(array('username' => $data['username'], 'password' => $data['password']), array('id', 'username'));
        if(empty($user) == false)
            return $user['Register'];
        return false;
    } 
public $validate = array(
        'first_name' => array(
        'rule' => 'notEmpty',
    'required' => true ,
    'message' => 'this field can not be set empty'
    ),
        'username' => array(
        'rule' => 'notEmpty'
        ),
    'password'=>array(
    'rule'=>'notempty'
    ),
    'cnfrmpassword'=>array(
    'rule'=>'notempty'
    )
    );
}
?>`

ビューコードは reg.ctpです

`<h2>Registration Form</h2>
<?php echo $this->Html->link('Register',array( 'action' => 'login')); 

echo $this->form->create('Register', array('action' => 'register'));
echo $this->form->input('first_name');
echo $this->form->input('username');
echo $this->form->input('password');
echo $this->form->input('cnfrmpassword', array('type' => 'password'));
echo $this->form->submit();
echo $this->form->end();
?>`

login.ctp

`<h1>Sign in form</h1>
    <?php
    echo $this->form->create('Register',array('action'=>'login'));
    echo $this->form->input('username');
    echo $this->form->input('password');
    echo $this->form->end('Sign in');
    ?>

<?php echo $this->Html->link('Logout', array('controller' => 'Registers', 'action' => 'logout')); ?>
<br/><br/>`

コントローラーコード

`<?
class RegistersController extends AppController
{
var $name = 'Register';
 var $helpers = array('Html', 'Form');
public function reg() {
      if (!empty($this->data))
         {
          
              $this->Register->create();
             // $this->Register->save($this->data);
              $this->redirect(array('action' => 'reg'));
          
      }
  }

public function register() {
        if ($this->request->is('post')) {
            if ($this->Register->save($this->request->data)) {
                $this->Session->setFlash('Your are registered');
                $this->redirect(array('action' => 'reg'));
            } else {
                $this->Session->setFlash('Unable to register');
        $this->redirect(array('action' => 'reg'));
            }
        }
    }
 function beforeFilter()
    {
        $this->__validateLoginStatus();
    } 
function login()
    {
        if(empty($this->data) == false)
        {
            if(($user = $this->Register->validateLogin($this->data['Register'])) == true)
            {
                $this->Session->write('Register', $user);
                $this->Session->setFlash('You\'ve successfully logged in.');
                $this->redirect('reg');
                exit();
            }
            else
            {
                $this->Session->setFlash('Sorry, the information you\'ve entered is incorrect.');
                exit();
            }
        }
    }
    
    function logout()
    {
        $this->Session->destroy('Register');
        $this->Session->setFlash('You\'ve successfully logged out.');
        $this->redirect('reg');
    } 


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.');
            }
        }
    }
    
}
?>`

あなたは秘密の安全な場所にアクセスしました!`

4

3 に答える 3

0

この行を変更します。

$user = $this->find(array('username' => $data['username'], 'password' => $data['password']), array('id', 'username'))

に:

$user = $this->find(array(conditions => array('username' => $data['username'], 'password' => $data['password'])), array('id', 'username'))

お役に立てれば

于 2014-02-01T05:24:04.977 に答える
0

細かいミスすいません。

これが微調整された答えです。

この行を変更します。

$user = $this->find(array('username' => $data['username'], 'password' => $data['password']), array('id', 'username'))

に:

$user = $this->find('first', array('conditions' => array('username' => $data['username'], 'password' => $data['password'])), array('id', 'username'))

お役に立てれば

于 2014-02-01T05:27:15.163 に答える