2014-07-16 91 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

回答