# |
Jul 30th 2021, 14:46 |
upgrad3d57 |
I just want to delete multiple records based off of a non-primary-key field. |
# |
Jul 30th 2021, 14:45 |
upgrad3d57 |
Anyone give support on why when I use $this->Model->deleteAll(['non_public_key' => $someId); it tells me that it's looking for the Model.id and can't find the field? (There is no ID field on that table) |
# |
Jul 28th 2021, 10:25 |
dereuromark |
@brandon if you want to avoid inline annotation use the props :) Thats why they are typed in annotations, and kept up to date using IdeHelper |
# |
Jul 28th 2021, 10:15 |
paolo.bragagni |
boolan filed is not marked as 'required' |
# |
Jul 28th 2021, 09:47 |
paolo.bragagni |
how to fire a provider rule only when create |
# |
Jul 28th 2021, 07:07 |
paolo.bragagni |
found thanks |
# |
Jul 28th 2021, 07:01 |
paolo.bragagni |
``` $validator->add('title', 'custom', [ 'rule' => 'nosame', 'provider'=>'custom', 'message'=>'custom message' ]); ``` |
# |
Jul 28th 2021, 07:00 |
paolo.bragagni |
how to pass $model? |
# |
Jul 28th 2021, 07:00 |
paolo.bragagni |
for example I'd like to not permit inserting same value so I have to access to model and make a query for $check in $model |
# |
Jul 28th 2021, 06:59 |
paolo.bragagni |
public function nosame($check,$model) : bool |
# |
Jul 28th 2021, 06:58 |
paolo.bragagni |
but How can I pass to it other variables? |
# |
Jul 28th 2021, 06:58 |
paolo.bragagni |
built a Provider and strange but true it works |
# |
Jul 28th 2021, 06:03 |
brandon |
I'm working on cleaning up my code with phpstan. One of the things it complains about a lot of `Access to an undefined property object::$var` for things like `Model->get()` where it can return the Model or an EntityInterface. Am I supposed to use the `@var` doc each time? Here is an example: ```$attribute = $this->AttributeValues->Attributes->get($attribute_id); $datetime = $attribute->type == 'datetime';``` phpstan complains: |
# |
Jul 28th 2021, 06:03 |
slackebot2 |
```Access to an undefined property Cake\Datasource\EntityInterface::$type.``` But if I add the following above the code, the error goes away ```/** @var \Inventory\Model\Entity\Attribute $attribute */``` What is the best practice here? Am I missing something? |
# |
Jul 28th 2021, 04:58 |
brandon |
Where do you put this config? Also, level 6!? Oof. |
# |
Jul 28th 2021, 03:56 |
rohit.onus |
Hi, Anyone using Mpdf library in cakephp 2 ? I'm getting error in load Mpdf library *Class 'Mpdf\Mpdf' not found.* |
# |
Jul 27th 2021, 22:39 |
cnizzardini |
Either hardcode on server or if you're using k8s in configmap or Swarm via env in docker compose. Depends on your infrastructure |
# |
Jul 27th 2021, 22:38 |
cnizzardini |
Yep that would cause it. Don't sent envars via nginx |
# |
Jul 27th 2021, 19:22 |
kevin.pfeifer |
or copy/write the string in a text file and view that file with a hexeditor to see what it actually is |
# |
Jul 27th 2021, 19:10 |
mrgrimpy |
I think I just found the problem. It's when I run bin/cake bake model from CLI (no environment variables). What would be the easiest workaround? |
# |
Jul 27th 2021, 19:01 |
mrgrimpy |
It's in the environment. What's even stranger is when I go in the env() function and I add `if ($val == 'DATABASE_FOO_URL') {` `dd($val):` `}` I get the DSN string. I'm very confused. |
# |
Jul 27th 2021, 18:58 |
kevin.pfeifer |
but yes, the whole encoding bullshit is such a mess |
# |
Jul 27th 2021, 18:58 |
kevin.pfeifer |
you could try https://github.com/neitanod/forceutf8 and see if that helps |
# |
Jul 27th 2021, 18:57 |
kevin.pfeifer |
well as the doc says for mb_detect_encoding() ```Detects the most likely character encoding for string string from an ordered list of candidates.``` |
# |
Jul 27th 2021, 18:54 |
greg138 |
So, this is weird. `mb_check_encoding($filename, 'UTF-8')` returns false. `mb_detect_encoding($filename)` returns "UTF-8"... |
# |
Jul 27th 2021, 18:46 |
paolo.bragagni |
I Need or now only dire One tabke and there are not one line logic. The problem Is that i am not able to write a provider... |
# |
Jul 27th 2021, 18:46 |
greg138 |
Is that actually in your environment, or using a `.env` file and importing that? |
# |
Jul 27th 2021, 18:40 |
mrgrimpy |
Hi, I'm encountering a weird problem today concerning my database configuration. I set an environment variable via fastcgi_param (DATABASE_FOO_URL) in my Nginx configuration containing a DSN string. Here is my entry in Datasources (app.php): `'foo' => [` `'url' => env('DATABASE_FOO_URL'),` `'className' => _Connection_::class,` `'driver' => |
# |
Jul 27th 2021, 18:40 |
slackebot2 |
_Mysql_::class,` `],` |
# |
Jul 27th 2021, 18:25 |
vinicius.big |
I'll check this, it seems the way to go! thanks! |
# |
Jul 27th 2021, 18:24 |
vinicius.big |
nice to meet you, Skie! LOL! |
# |
Jul 27th 2021, 18:23 |
skie956 |
You can use cakephp-fixture-factories from the seeds. It uses faker in background, and the nice thing that it can be configured to generate dependent data, with the root level entity. |
# |
Jul 27th 2021, 18:23 |
skie956 |
I am skie ;) |
# |
Jul 27th 2021, 18:22 |
vinicius.big |
Yeah,,, I'm already using Faker. Its a good approach... But I'm lookign for a easy way to create related data. And thats the goal of skie/cakephp-factory-muffin. Here a example of using it. |
# |
Jul 27th 2021, 18:21 |
cnizzardini |
Too bad the cakephp adpater is for 2.x |
# |
Jul 27th 2021, 18:19 |
cnizzardini |
I've heard of it, but never personally used it. |
# |
Jul 27th 2021, 18:18 |
cnizzardini |
@vinicius.big you can try something like this: https://github.com/fzaninotto/Faker |
# |
Jul 27th 2021, 18:10 |
vinicius.big |
yeah... I mean loading testing data, seeding the database. |
# |
Jul 27th 2021, 18:07 |
kevin.pfeifer |
I guess Vinicius Arantes means loading (test-)data into the “live” database. The fixture factories are only usable inside the tests as far as I know |
# |
Jul 27th 2021, 17:56 |
skie956 |
You can take a look into https://github.com/vierge-noire/cakephp-fixture-factories |
# |
Jul 27th 2021, 17:56 |
skie956 |
Wow, I even dont remember i did it. |
# |
Jul 27th 2021, 17:48 |
greg138 |
It came from the database, which is UTF-8, but I'll check this. |
# |
Jul 27th 2021, 17:47 |
kevin.pfeifer |
could be that the è is encoded in something other then UTF-8 |
# |
Jul 27th 2021, 17:46 |
kevin.pfeifer |
have you tried checking the string if its actually a valid UTF-8 string? ```mb_check_encoding($string, 'UTF-8');``` |
# |
Jul 27th 2021, 17:43 |
vinicius.big |
hey folks. There is any plugin/solution to create generate dummy data for my entities? For Cake4. The Real World Example App uses skie/cakephp-factory-muffin but its using Cake 3.8 Other examples on Cake awesome List are still using cake3 also. |
# |
Jul 27th 2021, 16:58 |
greg138 |
I know this is a little old, but I wouldn't think it would cause this sort of issue. |
# |
Jul 27th 2021, 16:58 |
greg138 |
```intl Internationalization support => enabled ICU version => 64.2 ICU Data version => 64.2 ICU TZData version => 2019a ICU Unicode version => 12.1``` |
# |
Jul 27th 2021, 16:53 |
slackebot2 |
(/var/www/cake3/vendor/cakephp/cakephp/src/I18n/Formatter/IcuFormatter.php:56)``` |
# |
Jul 27th 2021, 16:53 |
greg138 |
I'm running into a problem passing a UTF-8 string as a positional parameter in `__`. Anybody else see this? `$text = __('{0} {1} document {2}', $action, $category, $filename);` When `$filename` has something like "123 Des règles", we get ```[Aura\Intl\Exception\CannotFormat] Invalid UTF-8 data in string argument: '123 Des règles': U_INVALID_CHAR_FOUND |
# |
Jul 27th 2021, 16:51 |
greg138 |
If you only ever need the code in one place, then having it in that one place is more elegant; why have a whole separate file just to implement a one-line function? If you need it in multiple places, but all in the same table, then a function in that table is probably most elegant. If you need it across tables, then a provider gets to be a useful thing. |
# |
Jul 27th 2021, 16:13 |
paolo.bragagni |
...and now that I know about providers seems more elegant... :D |
# |
Jul 27th 2021, 16:12 |
paolo.bragagni |
Can I put custom logic in a method? |
# |
Jul 27th 2021, 16:11 |
paolo.bragagni |
Id like to reuse the custom logic |
# |
Jul 27th 2021, 15:59 |
tyler.adam.lazenby |
I finally got my ci to run properly |
# |
Jul 27th 2021, 15:36 |
kevin.pfeifer |
as cnizzardini already said above you don’t need to create a custom provider. Just use this approach: ```$validator->add('title', 'someuniquename', [ 'rule' => function ($value, $context) use ($extra) { // Custom logic that returns true/false }, 'message' => 'The title is not valid' ]);``` Custom Providers are just a tool to separate custom rules into its own file. |
# |
Jul 27th 2021, 15:33 |
paolo.bragagni |
Il try tomorrow. (Someting easier??) |
# |
Jul 27th 2021, 15:00 |
cnizzardini |
Name your class `MyProvider` is the standard |
# |
Jul 27th 2021, 14:59 |
greg138 |
Should be `'provider' => 'custom'`, no? |
# |
Jul 27th 2021, 14:53 |
paolo.bragagni |
no errors but no validator |
# |
Jul 27th 2021, 14:52 |
paolo.bragagni |
class myProvider { public function customMethod() { return false; } } |
# |
Jul 27th 2021, 14:52 |
paolo.bragagni |
in myProvider |
# |
Jul 27th 2021, 14:52 |
paolo.bragagni |
$validator = new Validator(); $validator->setProvider('custom', new \App\Model\myProvider()); $validator->add('descrizione', 'custom', [ 'rule' => 'customMethod', 'provider' => 'table' ]); |
# |
Jul 27th 2021, 14:51 |
paolo.bragagni |
then in my model table in initialize I wrote |
# |
Jul 27th 2021, 14:50 |
paolo.bragagni |
created myProvider.php in App/Model |
# |
Jul 27th 2021, 14:50 |
paolo.bragagni |
no bo |
# |
Jul 27th 2021, 14:48 |
paolo.bragagni |
no wait |
# |
Jul 27th 2021, 14:47 |
paolo.bragagni |
created myProvider.php in App/Model |
# |
Jul 27th 2021, 14:47 |
paolo.bragagni |
I'm not able |
# |
Jul 27th 2021, 14:34 |
admad |
4.3 will even support PHP 8.1 :) |
# |
Jul 27th 2021, 14:29 |
admad |
`void` can't be used with any other type. |
# |
Jul 27th 2021, 14:23 |
cnizzardini |
at least 4.2 should be |
# |
Jul 27th 2021, 14:23 |
cnizzardini |
it's not like cakephp 4 won't be supported for a very longtime, and its compatible with php 8 |
# |
Jul 27th 2021, 14:18 |
paolo.bragagni |
ok trying |
# |
Jul 27th 2021, 14:17 |
cnizzardini |
or the last thing in the posted snippet, which accepts a string at arg two, but the method must be static |
# |
Jul 27th 2021, 14:16 |
cnizzardini |
i'm guessing here, because i've never used them, but I imagine you could do this: `$validator->setProvider('custom', new \App\Any\Damn\Fqn\MyProvider());` |
# |
Jul 27th 2021, 14:15 |
cnizzardini |
where ever you want per the documentation |
# |
Jul 27th 2021, 14:15 |
paolo.bragagni |
where the provider logic goes? |
# |
Jul 27th 2021, 14:14 |
cnizzardini |
if you're not reusing the rule, i see no reason to create a provider and would just use a callback |
# |
Jul 27th 2021, 14:13 |
cnizzardini |
build the provider and inform Validator |
# |
Jul 27th 2021, 14:12 |
brandon |
Oof. I am only just getting around to upgrading the site 4.x. 5.x is coming this year? :cold_sweat: |
# |
Jul 27th 2021, 14:12 |
cnizzardini |
you can cargo cult something into existence |
# |
Jul 27th 2021, 14:12 |
cnizzardini |
```$validator = new Validator(); // Use an object instance. $validator->setProvider('custom', $myObject); // Use a class name. Methods must be static. $validator->setProvider('custom', 'App\Model\Validation');``` |
# |
Jul 27th 2021, 14:12 |
cnizzardini |
specifically: |
# |
Jul 27th 2021, 14:12 |
cnizzardini |
https://book.cakephp.org/4/en/core-libraries/validation.html#adding-validation-providers |
# |
Jul 27th 2021, 14:11 |
paolo.bragagni |
(if datetime I admit only date in italian, if decimal I admit only 2 decimal etc.. |
# |
Jul 27th 2021, 14:09 |
paolo.bragagni |
I'm trying to create a model.twig where I define my own default validation |
# |
Jul 27th 2021, 14:08 |
cnizzardini |
cool, i've seen lots of PR activity on it |
# |
Jul 27th 2021, 14:08 |
cnizzardini |
which i assume you might not need, especially for a one off validation, depends on what you're trying to do though... |
# |
Jul 27th 2021, 14:08 |
dereuromark |
@cnizzardini It is fair to expect somewhere this year, but usually there is no clear deadline on this. In the past it was often close to the CakeFest. |
# |
Jul 27th 2021, 14:08 |
paolo.bragagni |
probably |
# |
Jul 27th 2021, 14:07 |
cnizzardini |
i think you would need to create a custom provider? |
# |
Jul 27th 2021, 14:07 |
paolo.bragagni |
miss something? |
# |
Jul 27th 2021, 14:06 |
paolo.bragagni |
and then public function customvalidation($value,$context){ etc.. |
# |
Jul 27th 2021, 14:06 |
paolo.bragagni |
find this way (allowEmpty because otherwise the Helper shows it as required |
# |
Jul 27th 2021, 14:05 |
paolo.bragagni |
```$validator->allowEmpty('descrizione', true) ; $validator->add('descrizione',[ 'customvalidation'=>[ 'rule'=>'customvalidation', 'provider'=>'table', 'message'=>'custom message' ] ]);``` |
# |
Jul 27th 2021, 14:03 |
cnizzardini |
or this: `rule' => [$this, 'method'],` where I imagine 'methodName' must exist in your Table class |
# |
Jul 27th 2021, 14:03 |
kevin.pfeifer |
@paolo.bragagni https://book.cakephp.org/4/en/core-libraries/validation.html#using-custom-validation-rules |
# |
Jul 27th 2021, 14:02 |
cnizzardini |
```// Use a closure $extra = 'Some additional value needed inside the closure'; $validator->add('title', 'custom', [ 'rule' => function ($value, $context) use ($extra) { // Custom logic that returns true/false }, 'message' => 'The title is not valid' ]);``` |
# |
Jul 27th 2021, 14:02 |
cnizzardini |
@paolo.bragagni try using a callback |
# |
Jul 27th 2021, 14:01 |
cnizzardini |
on that note, since @dereuromark is in the room, maybe he can answer when cake 5 will be out, which will only support 8 i think? |