# |
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! |
# |
Dec 18th 2019, 10:43 |
challgren |
```$query = $articles->find()->contain('Comments', function (Query $q) { return $q->find('approved')->find('popular'); });``` |
# |
Dec 18th 2019, 10:41 |
javier.villanueva |
I have a custom finder in a table "Tasks" , Tasks belongsTo Users. If I find $this->Users->find()->contain(['Tasks']); Can I apply my custom finder ? |
# |
Dec 18th 2019, 10:37 |
rochasmarcelo |
remove composer.lock and update composer.json |
# |
Dec 18th 2019, 10:33 |
SvenBuis |
Yes, I will if I find any :) . To bad some of the 3rd party plugins I used are no longer maintained. Some I already had to fork to make them 3.8 compatible. If I find the time I will probably write my own plugin for those |
# |
Dec 18th 2019, 10:32 |
challgren |
And if the plugin doesn’t support cake 4.x help the community out and do a PR for 4.x support. Most 3.8 code should support 4.x without an issue |
# |
Dec 18th 2019, 10:31 |
SvenBuis |
So it might be possible to update cake and the plugin at once, that would be the easiest way hehe |