Log message #4264591

# At Username Text
# Jun 1st 2021, 18:17 kevin.pfeifer + i find it very suspect, that a theme developer tells you (a customer) to update a "library" the theme developer used to build the theme (which I still doubt) This should in my opinion always be the job of the theme developer, not the customer
# Jun 1st 2021, 18:11 kevin.pfeifer do you have a composer.json inside your theme
# Jun 1st 2021, 18:10 jonathan086 That is the reason why I contacted you.
# Jun 1st 2021, 18:10 jonathan086 Thanks Kevin! The developer told me to update the cake PHP.
# Jun 1st 2021, 17:47 kevin.pfeifer @jonathan086 your errors are related to your Wordpress Theme "Nova" not being compatible with your new PHP Version. So upgrade your Theme (if possible without changes, not always the case) But generally this is a CakePHP support channel, not a Wordpress Support channel and your error currently has nothing to do with cakephp
# Jun 1st 2021, 17:41 jonathan086 After updating the value of String to CakeText, I am getting this error: *Parse error*: syntax error, unexpected ‘new’ (T_NEW) in */var/www/vhosts/scainc.net/httpdocs/wp-content/themes/nova/app/libs/inflector.php* on line *300*
# Jun 1st 2021, 17:39 jonathan086 *Fatal error*: Cannot use ‘String’ as class name as it is reserved in */var/www/vhosts/scainc.net/httpdocs/wp-content/themes/nova/app/libs/string.php* on line *28*
# Jun 1st 2021, 17:39 jonathan086 https://www.scainc.net/
# Jun 1st 2021, 17:39 jonathan086 I am in need of help. I used a wordpress theme and its framework was built on CakePHP. Upon upgrading wordpress to the latest version, I had to move the PHP version to 7.*. After updating, I am getting the following error:
# Jun 1st 2021, 17:24 tyler.adam.lazenby I just tried with __invoke as returning false, and it is still doing that
# Jun 1st 2021, 17:18 tyler.adam.lazenby ```$rules->add(new NotHasOneAsFirstChar('phone', 'You cannot use 1 as the first character of a phone number.'), 'notHasOneAsFirstCharacter');```
# Jun 1st 2021, 17:18 slackebot return $value[0] != "1"; } protected function cleanValue(string $value): array|string|null { $pattern = "/[^0-9]+/"; $replacement = ""; return preg_replace($pattern, $replacement, $value); } }```
# Jun 1st 2021, 17:18 slackebot function __construct(string $field, ?string $message = null) { $this->_fields = $field; if ($message) { $this->message = $message; } else { $this->message = __("That value is invalid."); } } public function __invoke(EntityInterface $entity, array $options): bool { $value = $entity->get($this->_fields); $value = $this->cleanValue($value);
# Jun 1st 2021, 17:18 tyler.adam.lazenby ```<?php namespace App\Model\Rule; use Cake\Datasource\EntityInterface; class NotHasOneAsFirstChar { /** * Name of fields or fields that this rule should be applied to. * @var string */ protected string $_fields; /** * Default message that should be set. Default message is "That value is invalid.". * @var string|null */ protected ?string $message; public
# Jun 1st 2021, 17:17 tyler.adam.lazenby I am still struggling with this. All I am trying to do is prevent the user from putting 1 as the first character for their phone number. It is being passed with an input mask so that it is easier for the user to put it in. I can clean off the mask pretty easily. Once I have done that, my test is trying to pass "(123) 567-8910" so that it will fail the validation test. Bu the entity doesn't have any errors.
# Jun 1st 2021, 17:02 tyler.adam.lazenby ok, thanks
# Jun 1st 2021, 17:02 ndm Not at all, that's the save operation flow options. Simply store the constructor argument value in a property and use that in the invoke method.
# Jun 1st 2021, 17:02 tyler.adam.lazenby oh I see now
# Jun 1st 2021, 16:52 tyler.adam.lazenby Question... how would the $options parameter be used with that constructor?
# Jun 1st 2021, 16:40 tyler.adam.lazenby ok that should work
# Jun 1st 2021, 16:38 ndm Add a constructor that takes the name of the field that the rule should check.
# 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')); }```