We are moving our forum in GitHub Discussions. For questions about Phalcon v3/v4 you can visit here and for Phalcon v5 here.

custom work with ODM data


I have a data looks like :

{ "_id" : ObjectId("5485fff9cd4c5357388b4567"), 
"email" : "[email protected]", "password" : "$2a$08$ViYRn3IqwbjbF5MrAuatBOAOyopqVOuoKo7HBavBcp6ZfGV/3s7ky", 
"name" : "my name",
"profile" : { 
   "name" : "comp", 
   "state" : "AK", 
   "city" : "city", 
   "zip" : "07009" }, 
"d_created" : "", "d_changed" : "" }

I'm trying to create a custom form to modify that data.

class ProfileForm extends Form
    public function initialize($entity = null, $options = null)

        $name = new Text('name', array(
            'placeholder' => 'name',
            'class' => 'form-control'

        $email = new Email('cmp-city', array(
            'placeholder' => 'Email',
            'class' => 'form-control'

        /// validators go next

In controller file :

$user = User::findFirst(array(
     array('email' => $this->session->get('auth')['email'])

$form = new ProfileForm($user);

If form is not submitted yet, the fields will be prefilled with the data from $user...

But I'm not sure how to create a field with prefilled data: $user->profile['name'] ?


no way?

P.S. For now I stay with $this->tag-> setDefault($name, $value)


Two options:

  1. Use Entity for Profile part of user (encasulate this fields with another class) and then you can use this entity as form argument.

  2. I did some changes for Form class to make array naming convention for fields more usable for the vegas-cmf/forms library (https://github.com/vegas-cmf/forms). With this you can just name your fields like:
    $name = new Text('profile[name]', array(
        'placeholder' => 'name',
        'class' => 'form-control'

And Form class will do the magic ;)