# |
Dec 18th 2019, 13:45 |
kaliel |
i'm thinking to join the course "Getting started with CakePHP 4", but is that a live session ? |
# |
Dec 18th 2019, 13:21 |
pieceof |
check submit button is not type submit, force type button |
# |
Dec 18th 2019, 13:21 |
pieceof |
using js for post ? |
# |
Dec 18th 2019, 13:18 |
pieceof |
fast double click ? |
# |
Dec 18th 2019, 12:39 |
jotpe |
there's a redirect after saving |
# |
Dec 18th 2019, 12:39 |
jotpe |
yeah, but why should this happen? |
# |
Dec 18th 2019, 12:38 |
pieceof |
double posting? |
# |
Dec 18th 2019, 12:36 |
jotpe |
What could cause duplicate data in my db with different ids (added by add method with post data)? |
# |
Dec 18th 2019, 12:32 |
ashish_onmobile |
Hi |
# |
Dec 18th 2019, 12:11 |
neon1024 |
So your accessor method is available on the enitty |
# |
Dec 18th 2019, 12:11 |
neon1024 |
`'valueField' => function ($entity) { return $entity->get('full_name'); }` |
# |
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*]` |