Logs for #cakephp

Page 42 of 36,922, showing 100 records out of 3,692,143 total, starting on record 4,101, ending on 4,200

# At Username Text
# May 30th 2021, 14:57 kevin.pfeifer well $entity should be your $frat
# May 30th 2021, 14:57 etibor it shows everytime a validation error no matter field value
# May 30th 2021, 14:56 etibor i dont know what happened but adding the `!empty($entity->field)` to the end of the if, makes crashed the validator
# May 30th 2021, 14:41 kevin.pfeifer because rules are only checked after the validator above has succeeded
# May 30th 2021, 14:41 kevin.pfeifer if you require to have something selected you need to add that to the valditors
# May 30th 2021, 14:37 kevin.pfeifer which i like to do with `!empty($entity->field)`
# May 30th 2021, 14:37 kevin.pfeifer then you first need to check if they are present
# May 30th 2021, 14:37 kevin.pfeifer if you get warnings/errors because some properties are not set
# May 30th 2021, 14:35 etibor Or if($frat->_joinData->score > $frat->maximal || $frat->_joinData->score<1 || ($frat->_joinData->result != null)){ does not works too
# May 30th 2021, 14:34 etibor its just dont allow when the selected item is null i tried to add that exception: if($frat->_joinData->score > $frat->maximal || $frat->_joinData->score<1 || !is_null($frat->_joinData->result)){
# May 30th 2021, 14:33 etibor yes i did it, i added to the DocumentsTable
# May 30th 2021, 14:12 kevin.pfeifer so you can sort of create custom flash messages in your model even though you don’t have access to the flash component inside your model
# May 30th 2021, 14:12 kevin.pfeifer which can be extended in the model and later accessed in the controller
# May 30th 2021, 14:11 kevin.pfeifer basically I added a property to that class
# May 30th 2021, 14:04 kevin.pfeifer you added ```class ProjectsTable extends Table { public array $flash_errors = [];``` to your DocumentsTable?
# May 30th 2021, 14:03 etibor thank you Kevin its almost good: Undefined property `flash_errors`. You have not defined the `flash_errors` association on `App\Model\Table\DocumentsTable`.
# May 30th 2021, 13:59 kevin.pfeifer Projects is your Table of course
# May 30th 2021, 13:59 kevin.pfeifer ```if( $this->Projects->save( $project ) ) { $this->Flash->success( __d('alfred_projects', 'The project has been saved.' ) ); return $this->redirect( [ 'action' => 'edit', $project->id ] ); } else { if( sizeof( $this->Projects->flash_errors ) > 0 ) { foreach( $this->Projects->flash_errors as $error ) { $this->Flash->error( $error ); } } else {
# May 30th 2021, 13:59 slackebot $this->Flash->error( __d('alfred_projects', 'The project could not be saved. Please, try again.' ) ); } }```
# May 30th 2021, 13:58 kevin.pfeifer and access these messages in your controller
# May 30th 2021, 13:58 kevin.pfeifer ``` $rules->add(function ($entity, $options) { array_push( $this->flash_errors, "my error message" ); return false; }, 'ruleName', [ 'errorField' => 'is_done', 'message' => 'My custom message' ]);```
# May 30th 2021, 13:57 kevin.pfeifer ```class ProjectsTable extends Table { public array $flash_errors = [];```
# May 30th 2021, 13:57 kevin.pfeifer i guess it would be easier for you to set “custom error messages” like so
# May 30th 2021, 13:56 etibor $this->Form->control('storage.'.$i.'._joinData.score',['label'=>(false),    'type'=>'select','options'=>$options,'empty'=>__('choose') ]); // i have actually 4 fields like this
# May 30th 2021, 13:55 etibor if the error message is displayed on the top of the page it would be also good
# May 30th 2021, 13:55 etibor actually i have a field for total score, echo $this->Form->control( 'score' ); and if there is the custom error, the message is displayed there
# May 30th 2021, 13:51 slackebot <kevin.pfeifer>
# May 30th 2021, 13:51 kevin.pfeifer which results in
# May 30th 2021, 13:51 kevin.pfeifer ``` echo $this->Form->control( 'is_done' );```
# May 30th 2021, 13:50 kevin.pfeifer and my form outputs
# May 30th 2021, 13:50 kevin.pfeifer in my Table
# May 30th 2021, 13:50 kevin.pfeifer ``` public function buildRules( RulesChecker $rules ): RulesChecker { $rules->add(function ($entity, $options) { return false; }, 'ruleName', [ 'errorField' => 'is_done', 'message' => 'My custom message' ]); return $rules; }```
# May 30th 2021, 13:50 kevin.pfeifer let me explain how I got it working
# May 30th 2021, 13:47 etibor and the form is $this->Form->create($document)
# May 30th 2021, 13:47 etibor $this->Form->control('storage.'.$i.'._joinData.score',['label'=>(false), 'type'=>'select','options'=>$options,'empty'=>__('choose') ]);
# May 30th 2021, 13:45 kevin.pfeifer let me check that
# May 30th 2021, 13:45 etibor but that does not show the erro by that field
# May 30th 2021, 13:44 etibor i tried like this(just for give a try): ['errorField'=>'storage.0._joinData.score','message'=>'Do not change Form field values!']
# May 30th 2021, 13:43 etibor the fields look like this storage.$i._joinData.score
# May 30th 2021, 13:42 kevin.pfeifer ha ok
# May 30th 2021, 13:41 etibor the last thing would be to show the error message by the properly form field
# May 30th 2021, 13:41 kevin.pfeifer hello :)
# May 30th 2021, 13:41 etibor the solution almost work perfectly
# May 30th 2021, 13:40 etibor hello Kevin
# May 30th 2021, 08:26 kevin.pfeifer :clap: ndm
# May 30th 2021, 04:17 admad @ndm You are already the north star of this channel for quite a while, guiding the lost souls.
# May 30th 2021, 01:59 davinci nice!!! thanks!
# May 30th 2021, 01:47 ndm Other than custom associations like those, the pretty much only other option would be to manually load the associated results in a result formatter, where you have access to the binding key values. You'd have to use something similar with row numbering window functions, or you'd have to run one additional query per parent, which kinda sucks @davinci
# May 30th 2021, 01:39 ndm Now it's my time to shine :) https://github.com/icings/partitionable
# May 30th 2021, 01:23 davinci I'm sure I'm missing something obvious, but can't think of it
# May 30th 2021, 01:23 davinci Want to limit a contained data set to 10 Prices for each PriceSource, but doing it like this limits to 10 total: ```->contain([ 'PriceSources' => [ 'Prices' => function (Query $q) { return $q->where(['Prices.model'=>'Car', 'foreign_key'=>123456])->order(['Prices.date' => 'DESC'])->limit(10); }, ] ])```
# May 29th 2021, 22:50 kevin.pfeifer :+1::the_horns:
# May 29th 2021, 22:47 etibor Kevin thank you really much i think the hard part is over, now i hope i will manage if not i will ask a little more help nex time
# May 29th 2021, 22:43 kevin.pfeifer puh, dont really know. guess foreach
# May 29th 2021, 22:42 etibor or is there an easier way?
# May 29th 2021, 22:42 etibor should i go through wit a foreach ?
# May 29th 2021, 22:41 etibor yes beacuse on the form there are multiple score form fields
# May 29th 2021, 22:40 kevin.pfeifer but if at least you can get to the data ^^
# May 29th 2021, 22:40 kevin.pfeifer mhmm ok, could be that this is a difference from cake3 to 4
# May 29th 2021, 22:39 etibor the (false) data field is avaliable in a _joinData
# May 29th 2021, 22:29 etibor moment please
# May 29th 2021, 22:29 kevin.pfeifer before you call the save function
# May 29th 2021, 22:28 kevin.pfeifer do you contain the storage model?
# May 29th 2021, 22:28 kevin.pfeifer in your edit function
# May 29th 2021, 22:28 kevin.pfeifer ok and in your controller
# May 29th 2021, 22:28 etibor it does not show the Storage Model's field values
# May 29th 2021, 22:27 etibor okey var_dump helped to print out
# May 29th 2021, 22:26 kevin.pfeifer or after the add
# May 29th 2021, 22:25 kevin.pfeifer so like parallel to the add
# May 29th 2021, 22:25 kevin.pfeifer if you put a die outside of that function does it then stop?
# May 29th 2021, 22:24 kevin.pfeifer :thinking_face:
# May 29th 2021, 22:24 etibor but its just jump over and display save successfull message
# May 29th 2021, 22:24 etibor i tried to debug the entity: $rules->add(function ($entity, $options) {debug($entity);die;
# May 29th 2021, 22:24 kevin.pfeifer so like `$this->Documents->get($id)->contain('Storage')`
# May 29th 2021, 22:23 kevin.pfeifer when you do the save function on the entity it needs to already contain the connected data
# May 29th 2021, 22:22 kevin.pfeifer where i have my ->contain() in the query
# May 29th 2021, 22:22 etibor in an edit
# May 29th 2021, 22:22 kevin.pfeifer i just checked in the edit form before
# May 29th 2021, 22:21 kevin.pfeifer are you in an add form or in the edit form?
# May 29th 2021, 22:21 etibor are you sure "has already the connected entities in there" ?
# May 29th 2021, 22:21 kevin.pfeifer hmm
# May 29th 2021, 22:21 etibor i got this error Trying to get property 'max' of non-object
# May 29th 2021, 22:14 etibor if this will work you save me from a lot of stress
# May 29th 2021, 22:14 etibor i am going to implement
# May 29th 2021, 22:14 etibor :)
# May 29th 2021, 22:13 kevin.pfeifer otherwise you know where to find me ;P
# May 29th 2021, 22:12 kevin.pfeifer i hope with that rule your problem is solved
# May 29th 2021, 22:12 kevin.pfeifer dude wow, thank you ,:)
# May 29th 2021, 22:10 etibor Thank you Kevin really much your help, just think to your cake friend while having the coffe
# May 29th 2021, 22:06 kevin.pfeifer well I have a “Buy me a Coffee” Button on https://www.devguide.at/en/kategorie/backend/php/ if you really really really want to give me something But again, you don’t need to do that!
# May 29th 2021, 22:04 etibor i appreciate soo much and would like to offer a lunch for tommorow
# May 29th 2021, 22:03 kevin.pfeifer and like to help people :)
# May 29th 2021, 22:03 kevin.pfeifer i just really really like cakephp
# May 29th 2021, 22:03 kevin.pfeifer :,)
# May 29th 2021, 22:03 kevin.pfeifer no
# May 29th 2021, 22:03 etibor do you have a Patreon?
# May 29th 2021, 22:03 etibor okey Kevin you already helped me a lot thank you, i am going to try i am sure it will help
# May 29th 2021, 22:02 kevin.pfeifer ``` $rules->add(function ($entity, $options) { // Return a boolean to indicate pass/failure if($entity->score > $entity->storage->max || $entity->score < $entity->storage->min){ return false; } return true; }, 'ruleName');```
# May 29th 2021, 22:02 kevin.pfeifer so you need something like that
# May 29th 2021, 22:01 kevin.pfeifer don’t need to load them