2014-07-16 93 views
8

我對Phalcon相當陌生,我非常喜歡它,目前正在研究我的第一個項目,但是我目前遇到了ORM的一個問題。Phalcon保存不起作用

我似乎無法保存。

我的用戶模型目前有一個簡單的表格設置

ID(INT,PK) 名稱(字符串) 用戶名(字符串) 電子郵件(串) 有效(INT) createdDate(INT)

和我的模型,這些定義爲使用註解策略屬性:

<?php 

/** 
* Users class 
* 
* Represents Holla users 
* 
*/ 
class Users extends Phalcon\Mvc\Model 
{ 

/** 
* @Primary 
* @Identity 
* @Column(type="integer", nullable=false) 
*/ 
public $id; 

/** 
* @Column(type="string", length=70, nullable=false) 
*/ 
public $name; 

/** 
* @Column(type="string", length=70, nullable=false) 
*/ 
public $username; 

/** 
* @Column(type="string", length=256, nullable=false) 
*/ 
public $password; 

/** 
* @Column(type="integer", nullable=false) 
*/ 
public $active; 

/** 
* @Column(type="integer", nullable=false) 
*/ 
public $createdDate; 

我的初始化有以下幾點:

public function initialize() 
{ 

    $this->setSource('users'); 
    $this->hasManyToMany('id', 'UsersAttributes', 'userId', 'attributeId', 'Attributes', 'id', array('alias' => 'attributes')); 
    $this->hasMany('id', 'Status', 'userId'); 
    $this->hasMany('id', 'UsersNeighbors', 'userId'); 
    $this->hasMany('id', 'UsersFriends', 'userId'); 
    $this->hasMany('id', 'UsersNeighborhoods', 'userId'); 

} 

然後我有我指着一個方法在我的控制器,在那裏我做了一些cvalidation的一個簡單的登記表,然後嘗試做保存:

 $user = new Users(); 

     $user->name = $name; 
     $user->username = strtolower(str_replace(' ', '', $name)); 
     $user->password = $this->security->hash($password); 

     if($user->save()) 
     { 

      $this->flash->success('Registered successfully!'); 

      $this->session->set('auth', array(
       'id' => $user->id, 
       'name' => $user->name 
      )); 

      return $this->response->redirect('user/home'); 

     } 
     else 
     { 

      $this->flash->error('An error occured, unable to register'); 

      return $this->response->redirect(''); 

     } 

我已經安裝剖析保存到一個日誌和所有似乎當我做了登記發生:

[Wed, 16 Jul 14 21:46:44 +0000][INFO] SELECT IF(COUNT(*)>0, 1 , 0) FROM `INFORMATION_SCHEMA`.`TABLES` WHERE `TABLE_NAME`='users' 
[Wed, 16 Jul 14 21:46:44 +0000][INFO] DESCRIBE `users` 

那麼它只是我的端口通過與閃光燈錯誤主視圖「發生錯誤」,因爲我已經德罰款abovem,所以我有點卡住,爲什麼它不創建新用戶,只是在用戶保存返回false。

在此先感謝

+2

檢查'$用戶>的getMessages()'對於喜歡這裏的錯誤:http://docs.phalconphp.com/en/latest/reference/models.html#creating-updating -records – jodator

+0

@jodator感謝耶,工作,我得到了保存工作,想彈出它的答案,我會接受它? –

+1

我很高興幫助。提前致謝 :) – jodator

回答