# |
Jun 1st 2021, 16:37 |
tyler.adam.lazenby |
https://book.cakephp.org/4/en/orm/validation.html#creating-custom-rule-objects |
# |
Jun 1st 2021, 16:34 |
tyler.adam.lazenby |
```<?php namespace App\Model\Rule; use Cake\Datasource\EntityInterface; class NotHasOneAsFirstChar { public function __invoke(EntityInterface $entity, array $options) { $value = $entity->get('phone'); // This should be more dynamic return $value[0] != "1"; } }``` |
# |
Jun 1st 2021, 16:33 |
slackebot |
"desired" value name from the entity interface though |
# |
Jun 1st 2021, 16:33 |
tyler.adam.lazenby |
I am trying to make a new reuseable validation rule that will be able to check if the first character is "1". This will primarily be used on phone fields, but not all phone fields will be labeled as "phone". I am trying to figure out how to create this validation rule object to do that. The logic is pretty straight forward once I can get the deiried value. The documentation doesn't make it clear how to get the |
# |
Jun 1st 2021, 16:31 |
tyler.adam.lazenby |
Ok new question |
# |
Jun 1st 2021, 16:31 |
tyler.adam.lazenby |
interesting. |
# |
Jun 1st 2021, 16:30 |
admad |
So either check for PUT in your action or check for PUT or POST |
# |
Jun 1st 2021, 16:28 |
admad |
It always does |
# |
Jun 1st 2021, 16:28 |
tyler.adam.lazenby |
I see the form helper added that hidden field. When does the helper do that? Because this is the first time I have seen that |
# |
Jun 1st 2021, 16:28 |
admad |
You don't have to manually add any hidden field |
# |
Jun 1st 2021, 16:27 |
tyler.adam.lazenby |
ok |
# |
Jun 1st 2021, 16:27 |
tyler.adam.lazenby |
oh |
# |
Jun 1st 2021, 16:27 |
admad |
Just msg in channel instead of the unnecessary thread |
# |
Jun 1st 2021, 16:27 |
tyler.adam.lazenby |
I didn't add that hidden field, let me see if it is there |
# |
Jun 1st 2021, 16:26 |
admad |
But html forms can only do POST so PUT is emulated using a hidden _method field |
# |
Jun 1st 2021, 16:26 |
tyler.adam.lazenby |
Not sure what you mean by this? |
# |
Jun 1st 2021, 16:25 |
admad |
And edit action is PUT in REST terms |
# |
Jun 1st 2021, 15:50 |
tyler.adam.lazenby |
The form method says "post" but the method from `$this->request->getMethod()` is saying it is "put" |
# |
Jun 1st 2021, 15:47 |
tyler.adam.lazenby |
I just saw that the method is "put" instead of "post". Why would my form be doing that? |
# |
Jun 1st 2021, 15:38 |
slackebot |
'login', 'password', 'company_name', 'account_id' ]; $user_types = $this->Accounts->Users->UserTypes->find('list'); $accounts = $this->Accounts->find('list'); $this->set(compact('users', 'user_types', 'fields', 'accounts')); }``` |
# |
Jun 1st 2021, 15:38 |
slackebot |
($this->request->is('post')) { debug('post received'); dd($this->request->getData()); } if ($users->count() === 0) { $this->Flash->warning('No users are found'); return $this->redirect(['controller' => 'Accounts', 'action' => 'index']); } // Passed data $fields = [ 'id', 'user_type_id', 'first_name', 'last_name', 'phone', 'email', |
# |
Jun 1st 2021, 15:38 |
tyler.adam.lazenby |
```public function legacyConvert() { /** @var \App\Model\Entity\User|\Authentication\IdentityInterface $user */ $user = $this->Authentication->getIdentity(); if (!$user->is_admin) { $this->Flash->error('You are not authorized to view that.'); return $this->redirect('/'); } $users = $this->Accounts->Users->find(); $this->Authorization->applyScope($users, 'migrate'); if |
# |
Jun 1st 2021, 15:38 |
tyler.adam.lazenby |
Ok this is really strange behavior. I am simply trying to make sure that the post conditional code is contained with a post request. I have a form with a submit button, and i verified that the form's method is post. But when I try to make a post request, the code inside the post check isn't executed. |
# |
Jun 1st 2021, 12:41 |
paolo.bragagni |
hot to set date and numbers in italian (I mean dd/gg/YYYY) in search plugin? |
# |
Jun 1st 2021, 12:40 |
paolo.bragagni |
How to search between date with https://github.com/FriendsOfCake/search ? |
# |
Jun 1st 2021, 10:39 |
inoas |
We miss you over at irc.libra.chat after FN has been taken over by some billionaire - As it is forbidden to put this in a topic, I am certain posting this once in a while in the chat here is a good free speech measure of making sure we don't break up as a community |
# |
Jun 1st 2021, 09:55 |
paolo.bragagni |
ecc.. |
# |
Jun 1st 2021, 09:55 |
paolo.bragagni |
{% for field in fields %} {%- if propertySchema[field]['type'] in ['date', 'datetime', 'time'] %} |
# |
Jun 1st 2021, 09:55 |
paolo.bragagni |
done |
# |
Jun 1st 2021, 08:33 |
paolo.bragagni |
cant get the schema in my table.twig so cant use Bake.columnData(field, schema) to retrieve filedData |
# |
Jun 1st 2021, 07:57 |
kevin.pfeifer |
ah, good to know! thx |
# |
Jun 1st 2021, 07:55 |
jpramirez |
@kevin.pfeifer if you use the test suite light, you can activate the statistic tool, which will give you also information on how many tables were involved in your test, which you want low in order to speed up your tests. But `--log-junit` will definitely do the job. |
# |
Jun 1st 2021, 06:59 |
paolo.bragagni |
put this in my table.twig but it doesnt find the schema |
# |
Jun 1st 2021, 06:59 |
paolo.bragagni |
{% for field in fields %} {%- set fieldData = Bake.columnData(field, schema) %} |
# |
May 31st 2021, 17:23 |
kevin.pfeifer |
pretty nice |
# |
May 31st 2021, 17:23 |
kevin.pfeifer |
doing `phpunit --colors=always --log-junit "my_tests_log.xml"` also generates a XML which also contains the time for each function :) |
# |
May 31st 2021, 17:21 |
steinkel |
`time vendor/bin/phpunit --filter yourTest` :P |
# |
May 31st 2021, 17:17 |
kevin.pfeifer |
uh, didn’t think of the xdebug profiler :thinking_face: |
# |
May 31st 2021, 17:17 |
ndm |
Run the test suite with xdebug profiling enabled, or for some more caveman-ish approach, start a timer in `setup()` and stop and log it in `teardown()`. |
# |
May 31st 2021, 17:11 |
kevin.pfeifer |
so not the whole test-suite, more granular for each test |
# |
May 31st 2021, 17:10 |
kevin.pfeifer |
Is there an “easy” way to measure how long a phpunit test takes? I got the problem, that some of my tests take pretty long, but I don’t know which and going through over 700 tests can take quite some time. |