Virtual property getters go in the Entity classes not in the Table classes.

On Friday, September 5, 2014 3:57:30 PM UTC+2, Abdelmajid el Ibrahimi wrote:
>
> Hello,
>
> I used the virtualsfield function from the api but it doens't work what do 
> i do wrong.
>
> namespace App\Model\Table;
>
> use Cake\ORM\Table;
> use Cake\Validation\Validator;
>
> class DocentenTable extends Table {
>     protected function _getFullName() {
>         return $this->_properties['voornaam'] . '  ' .
>             $this->_properties['achternaam'];
>     }
>     
>     public function initialize(array $config) {
>         $this->belongsToMany('Klassen');
>         $this->addBehavior('Timestamp');
>     }
>     
>     public function validationDefault(Validator $validator) {
>         $validator
>                 ->notEmpty('voornaam');
>         return $validator;
>     }
> }
>
> public function add(){
>         $this->loadModel('Docenten');
>         $klas = $this->Klassen->newEntity($this->request->data);
>         if($this->request->is('post')){
>             if($this->Klassen->save($klas)){
>                 $this->Flash->success(__('De klas is opgeslagen.'));
>                 return $this->redirect(['action' => 'index']);
>             }
>             $this->Flash->error(__('Het toevoegen is niet gelukt.'));
>         }
>         $docenten = $this->Docenten->find('list',[
>                                                         'idField' => 
> 'docent_id',
>                                                         'valueField' => 
> 'full_name'
>                                                         ]);
>         $this->set('docenten',$docenten);        
>         $this->set('klas', $klas);
>     }
>
> But the full_name field is empty. 
>
>

-- 
Like Us on FaceBook https://www.facebook.com/CakePHP
Find us on Twitter http://twitter.com/CakePHP

--- 
You received this message because you are subscribed to the Google Groups 
"CakePHP" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/cake-php.
For more options, visit https://groups.google.com/d/optout.

Reply via email to