php – Phalcon保存不工作

前端之家收集整理的这篇文章主要介绍了php – Phalcon保存不工作前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我是Phalcon的新手,我非常喜欢它,目前正在研究我的第一个项目,但是我现在遇到了ORM的一个问题.

我似乎无法拯救.

我的用户模型目前有一个简单的表设置

id(int,PK)
名字(字符串)
用户名(字符串)
电邮(字符串)
活动(int)
createdDate(int)

我的模型使用注释策略将这些定义为属性

  1. <?PHP
  2.  
  3. /**
  4. * Users class
  5. *
  6. * Represents Holla users
  7. *
  8. */
  9. class Users extends Phalcon\Mvc\Model
  10. {
  11.  
  12. /**
  13. * @Primary
  14. * @Identity
  15. * @Column(type="integer",nullable=false)
  16. */
  17. public $id;
  18.  
  19. /**
  20. * @Column(type="string",length=70,nullable=false)
  21. */
  22. public $name;
  23.  
  24. /**
  25. * @Column(type="string",nullable=false)
  26. */
  27. public $username;
  28.  
  29. /**
  30. * @Column(type="string",length=256,nullable=false)
  31. */
  32. public $password;
  33.  
  34. /**
  35. * @Column(type="integer",nullable=false)
  36. */
  37. public $active;
  38.  
  39. /**
  40. * @Column(type="integer",nullable=false)
  41. */
  42. public $createdDate;

我的初始化有以下几点:

  1. public function initialize()
  2. {
  3.  
  4. $this->setSource('users');
  5. $this->hasManyToMany('id','UsersAttributes','userId','attributeId','Attributes','id',array('alias' => 'attributes'));
  6. $this->hasMany('id','Status','userId');
  7. $this->hasMany('id','UsersNeighbors','UsersFriends','UsersNeighborhoods','userId');
  8.  
  9. }

然后我有一个简单的注册表单,我指向我的一个控制器中的一个方法,我做了一些cvalidation,然后尝试进行保存:

  1. $user = new Users();
  2.  
  3. $user->name = $name;
  4. $user->username = strtolower(str_replace(' ','',$name));
  5. $user->password = $this->security->hash($password);
  6.  
  7. if($user->save())
  8. {
  9.  
  10. $this->flash->success('Registered successfully!');
  11.  
  12. $this->session->set('auth',array(
  13. 'id' => $user->id,'name' => $user->name
  14. ));
  15.  
  16. return $this->response->redirect('user/home');
  17.  
  18. }
  19. else
  20. {
  21.  
  22. $this->flash->error('An error occured,unable to register');
  23.  
  24. return $this->response->redirect('');
  25.  
  26. }

我已经设置了探查器以保存到日志中,当我进行注册时似乎发生的一切是:

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

然后它只是通过闪存错误“发生错误”将我引导到主视图,因为我已经在上面定义了所以我有点卡住为什么它不是创建新用户而只是在用户保存时返回false .

提前致谢

使用$user-> getMessages()检查错误总是有助于调试$model-> save()的错误.

更多信息:http://docs.phalconphp.com/en/latest/reference/models.html#creating-updating-records

猜你在找的PHP相关文章