2014-07-16 16 views
8

Sono abbastanza nuovo per Phalcon, mi piace molto, attualmente sto lavorando al mio primo progetto, ma attualmente sto riscontrando un problema con l'ORM.Phalcon save not working

Mi sembra di non essere in grado di salvare.

Il mio modello utenti attualmente ha una configurazione semplice tavolo

id (int, PK) nome (stringa) nome utente (stringa) e-mail (string) attiva (int) createdDate (int)

e il mio modello è definito come queste proprietà utilizzando la strategia di annotazioni:

<?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; 

mio inizializzazione ha il seguente:

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'); 

} 

Ho poi ho un semplice modulo di registrazione che sto indicando un metodo in uno dei miei regolatori di cui faccio un po cvalidation, quindi si tenta di fare il salvataggio:

 $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(''); 

     } 

Ho installato il profiler per salvare in un registro e tutto ciò che sembra accadere quando faccio una registrazione è:

[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` 

poi appena mi porti fino alla vista principale con l'errore flash "è verificato un errore", come ho de abovem multato quindi sono un po 'bloccato dal fatto che non stia creando il nuovo utente e restituendo false su user save.

Grazie in anticipo

+2

Controllare '$ user-> getMessages()' per errori come qui: http://docs.phalconphp.com/en/latest/reference/models.html#creating-updating -records – jodator

+0

@jodator Grazie Sì che ha funzionato e ho ottenuto il salvataggio al lavoro, voglio farlo scoppiare in una risposta e lo accetterò? –

+1

Sono contento che abbia aiutato. Grazie in anticipo :) – jodator

risposta