# |
Dec 18th 2019, 12:10 |
neon1024 |
You’ve passed the trainer entity into your callback |
# |
Dec 18th 2019, 12:03 |
gianmarxgagliardi |
also your solution works thanks a lot |
# |
Dec 18th 2019, 12:02 |
jotpe |
Yeah, but maybe you want to access the full name somewhere else in your app ;) |
# |
Dec 18th 2019, 12:01 |
gianmarxgagliardi |
`$trainersUnmated=$this->SeasonTrainers->Trainers->find('list',['keyField' => 'id',` `'valueField' =>function($trainer){` `return $trainer->cognome .' '. $trainer->nome;` `}])->notMatching('SeasonTrainers');` it's works |
# |
Dec 18th 2019, 12:00 |
jotpe |
`$trainersUnmated = $this->SeasonTrainers->Trainers->find('list', ['keyField' => 'id', 'valueField' => *$full_name*])->notMatching('SeasonTrainers');` |
# |
Dec 18th 2019, 12:00 |
jotpe |
With your Accessor (`_getFullName()`) in your Trainer Entity you can access the full name. The query `$trainersUnmated = $this->SeasonTrainers->Trainers->find('list', ['keyField' => 'id', 'valueField' => $trainer->full_name])->notMatching('SeasonTrainers');` must be changed |
# |
Dec 18th 2019, 11:59 |
gianmarxgagliardi |
the problem is to call the method written in the model of trainers in the seasons_trainers controller |
# |
Dec 18th 2019, 11:58 |
jotpe |
Your query is not correct. |
# |
Dec 18th 2019, 11:57 |
jotpe |
? |
# |
Dec 18th 2019, 11:56 |
gianmarxgagliardi |
```<?php $query = $articles->find('list', [ 'keyField' => 'id', 'valueField' => function ($article) { return $article->author->get('label'); } ]);``` develop internal function and concat from there |
# |
Dec 18th 2019, 11:55 |
gianmarxgagliardi |
I think it is better for me to start again from this function |
# |
Dec 18th 2019, 11:47 |
slackebot |
<gianmarxgagliardi> |
# |
Dec 18th 2019, 11:45 |
jotpe |
`debug($trainersUnmated->toArray())` |
# |
Dec 18th 2019, 11:44 |
gianmarxgagliardi |
https://pastebin.com/ujnvV3NA |
# |
Dec 18th 2019, 11:42 |
jotpe |
@gianmarxgagliardi Your Entity Accessor for the full_name looks good. What happens if you debug your query? Try to `debug($trainersUnmated)` |
# |
Dec 18th 2019, 11:37 |
gianmarxgagliardi |
I tried to follow the link example. There must be a problem calling a function `full_name` of the model>entity trainers in the seasons_trainings controller |
# |
Dec 18th 2019, 11:34 |
slackebot |
<gianmarxgagliardi> |
# |
Dec 18th 2019, 11:33 |
gianmarxgagliardi |
`$trainersUnmated=$this->SeasonTrainers->Trainers->find('list',['keyField' => 'id',` `'valueField' =>$trainer->full_name])->notMatching('SeasonTrainers');` |
# |
Dec 18th 2019, 11:33 |
gianmarxgagliardi |
then I should call it up in SeasonTrainersController.php |
# |
Dec 18th 2019, 11:32 |
gianmarxgagliardi |
`protected function _getFullName()` `{` `return $this->cognome . ' ' . $this->nome;` `}` |
# |
Dec 18th 2019, 11:31 |
gianmarxgagliardi |
I defined this function in the model> entity> Trainer.php |
# |
Dec 18th 2019, 11:31 |
neon1024 |
You’re accessing an entity which is a php class |
# |
Dec 18th 2019, 11:30 |
neon1024 |
As before, it would only work with something which uses the Hash library in the background |
# |
Dec 18th 2019, 11:29 |
gianmarxgagliardi |
oddly I saw it worked compared to `$trainer->full_name` |
# |
Dec 18th 2019, 11:28 |
gianmarxgagliardi |
that was a typo `$trainer.full_name` |
# |
Dec 18th 2019, 11:27 |
neon1024 |
Unless you did lots of Javascript or something and got confused I suppose |
# |
Dec 18th 2019, 11:26 |
neon1024 |
This was another reason why I asked about previous PHP experience. Most people would see that `$trainer.full_name` this isn’t valid PHP |
# |
Dec 18th 2019, 11:26 |
gianmarxgagliardi |
I followed this guide https://book.cakephp.org/3/en/orm/entities.html#creating-virtual-fields. |
# |
Dec 18th 2019, 11:25 |
dereuromark |
you need to use valid PHP here. What is the value of $trainer? wrap it in " or alike. |
# |
Dec 18th 2019, 11:23 |
gianmarxgagliardi |
> if I put `$trainer->full_name` return > `*Notice* (8): Undefined variable: trainer [*APP/Controller\SeasonTrainersController.php*, line *62*]` > `*Notice* (8): Trying to get property 'full_name' of non-object [*APP/Controller\SeasonTrainersController.php*, line *62*]` |
# |
Dec 18th 2019, 11:19 |
dereuromark |
$trainer.full_name is not valid PHP |
# |
Dec 18th 2019, 11:17 |
gianmarxgagliardi |
@dereuromark I'm confused ? what do you mean ? |
# |
Dec 18th 2019, 11:16 |
gianmarxgagliardi |
`$trainersUnmated=$this->SeasonTrainers->Trainers->find('list',['keyField' => 'id', 'valueField' =>$trainer.full_name])->notMatching('SeasonTrainers');` |
# |
Dec 18th 2019, 11:16 |
gianmarxgagliardi |
in model `protected function _getFullName()` `{` `return $this->cognome . ' ' . $this->nome;` `}` |
# |
Dec 18th 2019, 11:15 |
dereuromark |
avoid using custom constants :) |
# |
Dec 18th 2019, 11:14 |
gianmarxgagliardi |
it works but it gives me some warnings ```Warning (2): Use of undefined constant full_name - assumed 'full_name' (this will throw an Error in a future version of PHP) [APP/Controller\SeasonTrainersController.php, line 62]``` |
# |
Dec 18th 2019, 11:09 |
gianmarxgagliardi |
it's works thanks |
# |
Dec 18th 2019, 10:54 |
challgren |
Virtual fields would be your friend |
# |
Dec 18th 2019, 10:54 |
challgren |
@gianmarxgagliardi https://book.cakephp.org/3/en/orm/entities.html#creating-virtual-fields |
# |
Dec 18th 2019, 10:53 |
gianmarxgagliardi |
in this way it returns the fields "name" and "surname" divided by a semicolon to avoid this I have to write a separate function or there is another way `$trainersUnmated=$this->SeasonTrainers->Trainers->find('list',['keyField' => 'id','valueField' =>['name','surname']])->notMatching('SeasonTrainers');` the result I get is e.g. `John; Milton` but I would like `John Milton` |
# |
Dec 18th 2019, 10:45 |
javier.villanueva |
thanks! |