# |
Dec 2nd 2017, 19:45 |
obinoob |
hello, I been fighting hasMany association for a couple of day now, I can add / delete / list but not update! Validation rules keep firing errors "already in database" for Phones and Emails... https://gist.github.com/obinoob/e72c43d61875a0576c0ee97e121a44ef |
# |
Dec 2nd 2017, 12:27 |
angelxmoreno |
@dereuromark I will check the form helper class sir |
# |
Dec 2nd 2017, 06:07 |
admad |
make the users relogin or implement refresh tokens yourself :slightly_smiling_face: |
# |
Dec 2nd 2017, 04:23 |
prepender |
how do you guys handle expired jwt tokens on mobile apps? do you store their login credentials to refresh the token? i notice most out of the box jwt token solutions dont have resfresh endpoints and I wonder what the assumed method of refreshing would be? |
# |
Dec 2nd 2017, 01:58 |
dereuromark |
angel: did you solve it? passing the form into the formhelper should help, that uses its schema |
# |
Dec 2nd 2017, 00:03 |
obinoob |
back tomorrow have a good night/day to you all cheers :) |
# |
Dec 1st 2017, 23:47 |
obinoob |
I could unsetProperty I guess but not sure how with mass assignment https://github.com/cakephp/cakephp/issues/4288 |
# |
Dec 1st 2017, 23:42 |
phantomwatson |
The SQL statement `DELETE FROM phones WHERE number IS NULL` should do it. |
# |
Dec 1st 2017, 23:40 |
phantomwatson |
But concerning the unwanted database records, you'll need to either remove those manually or write a script that searches through the database and removes them. Just changing CakePHP's validation rules and form-processing logic won't automatically change any existing records in the database. |
# |
Dec 1st 2017, 23:38 |
phantomwatson |
Then to be safe, have some server-side logic that checks that data and returns an error if no phone numbers have been entered. This is just in case the client-side validation fails. |
# |
Dec 1st 2017, 23:36 |
phantomwatson |
You want to make the first phone number field required but not the second one? You'll likely need to make _neither_ of them required in your validation rules, then manually set `$this->Form->control('number', ['required' => true]);` for your first phone number input field. |
# |
Dec 1st 2017, 23:34 |
obinoob |
sorry method :) |
# |
Dec 1st 2017, 23:34 |
obinoob |
? It makes no sense to me that cake has no such future.... |
# |
Dec 1st 2017, 23:34 |
obinoob |
phantomwatson I've found that public function beforeSave method is not triggered from controller but from table... the problem is that beforeSave($event, $entity, $options) { ... } in table has access at one entity at a time, not to all of the entities.... also how can I mark only one phone number as obligatory without refactoring the all database |
# |
Dec 1st 2017, 23:24 |
phantomwatson |
*Answering my own question:* Turns out I should have been using `$this->request->getEnv('FOO')` to read the variable instead of `env('FOO')`. |
# |
Dec 1st 2017, 23:07 |
d-fens |
why doesn't the baked code order by id , iirc that was default in older versions? |
# |
Dec 1st 2017, 23:04 |
phantomwatson |
I'm avoiding `configRequest()` to stay DRY and avoid having to duplicate the other environment variables that are set in this test class's `setUp()` method. |
# |
Dec 1st 2017, 23:00 |
phantomwatson |
In other words, this is my situation: ``` // In test public function testFoo() { $this->_request['environment']['FOO'] = 'bar'; $this->get('/login'); } // In controller public function login() { debug(env('FOO')); // expected: 'bar'; actual: null } ``` |
# |
Dec 1st 2017, 22:27 |
phantomwatson |
In an integration test, I'm using `$this->configRequest(['environment' => ['foo' => 'bar']])` to set an environment variable before a request, but in the controller method that gets executed, the `foo` env var is always the default value, and `configRequest()` doesn't seem to be doing what I intend it to. Does anyone have any advice about setting env vars in an integration test? |
# |
Dec 1st 2017, 22:26 |
angelxmoreno |
something tells me @dereuromark already has the solution hidden somewhere :P |
# |
Dec 1st 2017, 22:26 |
angelxmoreno |
Greetings bakers! I am working with a CakeForm class and I am defining its schema. I feel weird having to change the view when I change the form object in order to add new fields. It feels "uncake-like". Is there an undocumented helper that takes the form object and creates the view using the already defined schema in the Form object? |
# |
Dec 1st 2017, 21:51 |
obinoob |
phantomwatson actually I can only see beforeSave in table and data it will be accessed with $event->getData('entity) https://book.cakephp.org/3.0/en/controllers/components/authentication.html |
# |
Dec 1st 2017, 21:47 |
obinoob |
and my english doesn't help much either |
# |
Dec 1st 2017, 21:46 |
obinoob |
I thought that cake had some key value option to do this kind of work hidden in the book somewhere... |
# |
Dec 1st 2017, 21:45 |
phantomwatson |
It definitely takes some work. Remember to check https://stackoverflow.com/ for answers too. |
# |
Dec 1st 2017, 21:44 |
obinoob |
*I'm |
# |
Dec 1st 2017, 21:44 |
obinoob |
I starting now with events so it is a total new thing for me today i've used for the first time beforeMarshal() I'm alone here man only count with channel help and cake website it's hard some times I take more than a day to achieve some basic stuff! |
# |
Dec 1st 2017, 21:42 |
phantomwatson |
It's okay. This stuff is complicated. |
# |
Dec 1st 2017, 21:41 |
obinoob |
yes I got that I wasn't paying attention I apologise |
# |
Dec 1st 2017, 21:41 |
phantomwatson |
So the code that I posted would normally be wrapped in `if ($this->request->is('post') {}` |
# |
Dec 1st 2017, 21:41 |
obinoob |
sorry I was read https://book.cakephp.org/3.0/en/orm/table-objects.html#beforesave |
# |
Dec 1st 2017, 21:40 |
phantomwatson |
The code that I posted was in the context of a controller method. `$this->request` isn't available in a table. |
# |
Dec 1st 2017, 21:39 |
obinoob |
beforeSave() in table right? |
# |
Dec 1st 2017, 21:37 |
obinoob |
and make them ->empty('number') |
# |
Dec 1st 2017, 21:37 |
phantomwatson |
Like ``` $data = $this->request->getData(); foreach ($data as $datum) { ... (if a number is empty(), remove that 'Phone' member from $data) ... } ``` |
# |
Dec 1st 2017, 21:36 |
phantomwatson |
Though there's likely a more elegant solution involving putting that logic in a `beforeSave()` callback. |
# |
Dec 1st 2017, 21:36 |
phantomwatson |
If it were me, I'd loop through the request data and remove empty phone numbers before saving. |
# |
Dec 1st 2017, 21:34 |
obinoob |
the thing is how can it be done? |
# |
Dec 1st 2017, 21:34 |
obinoob |
exactly |
# |
Dec 1st 2017, 21:34 |
phantomwatson |
It sounds like you need to actually `allowEmpty('number')` and then add some logic in your controller or `PhonesTable` that ignores any `Phone`s with empty numbers instead of saving them to the database. |
# |
Dec 1st 2017, 21:32 |
phantomwatson |
Is there any error that is still occurring that you would like help solving? |