# |
Jul 12th 2021, 19:51 |
tyler.adam.lazenby |
lets see if update changes the value |
# |
Jul 12th 2021, 19:50 |
tyler.adam.lazenby |
hmmm |
# |
Jul 12th 2021, 19:50 |
tyler.adam.lazenby |
except |
# |
Jul 12th 2021, 19:50 |
cnizzardini |
cool, again, id test various scenarios with that |
# |
Jul 12th 2021, 19:50 |
tyler.adam.lazenby |
its used in API calls |
# |
Jul 12th 2021, 19:50 |
tyler.adam.lazenby |
Because this value should never be user created |
# |
Jul 12th 2021, 19:49 |
tyler.adam.lazenby |
before marshall works here |
# |
Jul 12th 2021, 19:49 |
kevin.pfeifer |
behaviors are just re-usable model logic which can be applied to multiple models like components are to controllers |
# |
Jul 12th 2021, 19:48 |
kevin.pfeifer |
I am not aware of what the “best practice” for that would be Its just that I am aware of either the controller method or the template (set input value) method |
# |
Jul 12th 2021, 19:48 |
cnizzardini |
behavior is another way to try, thats how the timestamp stuff works I believe |
# |
Jul 12th 2021, 19:47 |
cnizzardini |
kevins approach might be best, its more obvious, idk, you have options though |
# |
Jul 12th 2021, 19:47 |
tyler.adam.lazenby |
I am testing it |
# |
Jul 12th 2021, 19:47 |
cnizzardini |
haven't actually tried using beforeMarshal for this purpose |
# |
Jul 12th 2021, 19:46 |
cnizzardini |
or overwrite an existing value because it was not present in the update |
# |
Jul 12th 2021, 19:46 |
cnizzardini |
wouldn't want to default to a value on an update if the user supplied a value |
# |
Jul 12th 2021, 19:46 |
kevin.pfeifer |
in my opinion |
# |
Jul 12th 2021, 19:46 |
kevin.pfeifer |
i understand why setting default values in the models seems fine but depending on your model/data you could run in the use case, that you need different default values depending on the situation Therefore it would be better to create an empty entity, patch the default value and then patch the input data |
# |
Jul 12th 2021, 19:46 |
cnizzardini |
id do some testing around create vs update with that though |
# |
Jul 12th 2021, 19:45 |
cnizzardini |
https://book.cakephp.org/4/en/orm/saving-data.html#modifying-request-data-before-building-entities |
# |
Jul 12th 2021, 19:44 |
tyler.adam.lazenby |
I am |
# |
Jul 12th 2021, 19:44 |
cnizzardini |
then try beforeMarshall |
# |
Jul 12th 2021, 19:44 |
tyler.adam.lazenby |
That feels "stinky" |
# |
Jul 12th 2021, 19:44 |
cnizzardini |
nothing wrong with doing it in the controller either |
# |
Jul 12th 2021, 19:44 |
tyler.adam.lazenby |
hmmmmm |
# |
Jul 12th 2021, 19:44 |
cnizzardini |
so beforeMarshall could be an option |
# |
Jul 12th 2021, 19:43 |
tyler.adam.lazenby |
```public function _setToken($token = null): string { if (!$token) { return Security::randomString(32); } return $token; }``` |
# |
Jul 12th 2021, 19:43 |
tyler.adam.lazenby |
Dang it, the entity doesn't save it by default |
# |
Jul 12th 2021, 19:42 |
japerlman |
yeah I keep getting the cake 3 docs and it takes me longer than it should to realize |
# |
Jul 12th 2021, 19:42 |
japerlman |
thanks for the help |
# |
Jul 12th 2021, 19:42 |
japerlman |
ok yeah it was the missing use, sorry guys. |
# |
Jul 12th 2021, 19:41 |
cnizzardini |
i suppose it would fail on marshall if not set before |
# |
Jul 12th 2021, 19:41 |
kevin.pfeifer |
i was just looking at https://stackoverflow.com/questions/8344189/cakephp-set-default-field-values-in-the-model |
# |
Jul 12th 2021, 19:40 |
tyler.adam.lazenby |
the entity is the best place for this I think |
# |
Jul 12th 2021, 19:40 |
tyler.adam.lazenby |
I agree with kevin |
# |
Jul 12th 2021, 19:40 |
kevin.pfeifer |
i would guess the default value shoul be present before the save is being triggered |
# |
Jul 12th 2021, 19:40 |
cnizzardini |
im surprised there is no option for this in Entity |
# |
Jul 12th 2021, 19:40 |
kevin.pfeifer |
well, i looked at the cake3 doc, not the cake4…damn google, why do you still rank 3 higher than 4 |
# |
Jul 12th 2021, 19:39 |
cnizzardini |
and set the value of its null or whatever |
# |
Jul 12th 2021, 19:39 |
cnizzardini |
you could use a beforeSave |
# |
Jul 12th 2021, 19:39 |
tyler.adam.lazenby |
I like the idea of a field rule that will be system wide to be on the model and not action specific |
# |
Jul 12th 2021, 19:39 |
tyler.adam.lazenby |
Exactly |
# |
Jul 12th 2021, 19:38 |
cnizzardini |
that seems odd, what if the entity is created elsewhere too? |
# |
Jul 12th 2021, 19:38 |
dereuromark |
It is actually EventInterface :P but no biggy |
# |
Jul 12th 2021, 19:38 |
kevin.pfeifer |
otherwise you could set the default value on the field as well i guess |
# |
Jul 12th 2021, 19:38 |
kevin.pfeifer |
so in the empty entity when your in the add function e.g. |
# |
Jul 12th 2021, 19:38 |
tyler.adam.lazenby |
really? |
# |
Jul 12th 2021, 19:38 |
kevin.pfeifer |
default values should be set in the controller as far as I know |
# |
Jul 12th 2021, 19:37 |
tyler.adam.lazenby |
yeah |
# |
Jul 12th 2021, 19:37 |
cnizzardini |
maybe the entity |
# |
Jul 12th 2021, 19:36 |
tyler.adam.lazenby |
I think this should be on the table/model but I am not sure where I would do that |
# |
Jul 12th 2021, 19:36 |
cnizzardini |
^ yes |
# |
Jul 12th 2021, 19:36 |
kevin.pfeifer |
So if no FQCN is set it tries to autoload the Event class from the point where its currently at… |
# |
Jul 12th 2021, 19:36 |
tyler.adam.lazenby |
Is there a way to specify a default value for a field? For example, a way to make it so that the system generates a token using the Security randomChar() method |
# |
Jul 12th 2021, 19:34 |
cnizzardini |
will `return false;` actually stop a save? |
# |
Jul 12th 2021, 19:34 |
kevin.pfeifer |
add `use Cake\Event\Event;` at the top |
# |
Jul 12th 2021, 19:34 |
dereuromark |
Someone should be using an IDE like phpstorm |
# |
Jul 12th 2021, 19:34 |
dereuromark |
He is just missing use statements. |
# |
Jul 12th 2021, 19:33 |
japerlman |
https://stackoverflow.com/questions/2868665/is-there-a-better-way-to-change-user-password-in-cakephp-using-auth |
# |
Jul 12th 2021, 19:33 |
japerlman |
I don't believe so no, I'm just trying to cake4 this old cake2(maybe?) example of what I'm trying to do |
# |
Jul 12th 2021, 19:33 |
kevin.pfeifer |
do you have a custom class there? |
# |
Jul 12th 2021, 19:32 |
kevin.pfeifer |
what even is `App\Model\Table\Event` |
# |
Jul 12th 2021, 19:30 |
japerlman |
4 |
# |
Jul 12th 2021, 19:30 |
kevin.pfeifer |
which cakephp version are you on? |
# |
Jul 12th 2021, 19:29 |
kevin.pfeifer |
but wait |
# |
Jul 12th 2021, 19:28 |
kevin.pfeifer |
well, use the right `use` statements |
# |
Jul 12th 2021, 19:28 |
japerlman |
```Argument 1 passed to App\Model\Table\UsersTable::beforeSave() must be an instance of App\Model\Table\Event, instance of Cake\Event\Event given``` |
# |
Jul 12th 2021, 19:28 |
japerlman |
yeah that makes it very angry. |
# |
Jul 12th 2021, 19:26 |
kevin.pfeifer |
I would say you are missing the 3 parameters that are present in that hook ```beforeSave(Event $event, EntityInterface $entity, ArrayObject $options)``` |
# |
Jul 12th 2021, 19:25 |
japerlman |
I have that just as a troubleshooting step because beforeSave wasn't acting as I expected |
# |
Jul 12th 2021, 19:25 |
japerlman |
``` public function beforeSave() { return false; }``` |
# |
Jul 12th 2021, 19:25 |
japerlman |
I have this in my src/model/table/usertable.php and I can still edit/save users, I feel like I'm doing something very stupid and is hopefully a simple fix. |
# |
Jul 12th 2021, 19:22 |
kevin.pfeifer |
unless you manually set (or unset) the prefix |
# |
Jul 12th 2021, 19:20 |
kevin.pfeifer |
as far as I know all generated links follow the current prefix (if there is one set) |
# |
Jul 12th 2021, 18:44 |
tyler.adam.lazenby |
https://book.cakephp.org/4/en/development/routing.html#prefix-routing |
# |
Jul 12th 2021, 18:44 |
tyler.adam.lazenby |
`'prefix' => false` |
# |
Jul 12th 2021, 18:43 |
tyler.adam.lazenby |
ok I finally found out how to make link ignore the current prefix |
# |
Jul 12th 2021, 18:32 |
tyler.adam.lazenby |
but when I am not on a page with the admin prefix, it doesn't do that |
# |
Jul 12th 2021, 18:32 |
tyler.adam.lazenby |
And that means that links like contacts, messages, etc shouldn't be able to use the admin prefix. The URL route builder is adding that to the link when I am on a page under the admin prefix |
# |
Jul 12th 2021, 18:31 |
tyler.adam.lazenby |
But accounts is the only controller in the admin folder |
# |
Jul 12th 2021, 18:31 |
tyler.adam.lazenby |
One is accounts and the other admin/accounts |
# |
Jul 12th 2021, 18:30 |
tyler.adam.lazenby |
There are two different controllers |
# |
Jul 12th 2021, 18:28 |
kevin.pfeifer |
or should one redirect to the other |
# |
Jul 12th 2021, 18:27 |
kevin.pfeifer |
but both urls should result in the same? |
# |
Jul 12th 2021, 18:27 |
tyler.adam.lazenby |
Ok I just started experimenting with prefixes, and I noticing that ALL links are now being prefixed with my admin prefix. I only wanted to have the prefix be used by the URL builder if I explicitly used the admin prefix... how do I get my links back to not being prefixed and still keep the ability to prefix |
# |
Jul 12th 2021, 18:26 |
tyler.adam.lazenby |
nice |
# |
Jul 12th 2021, 17:16 |
kevin.pfeifer |
but little me thought "lordsimal" was a good nickname 13 years ago |
# |
Jul 12th 2021, 17:15 |
tyler.adam.lazenby |
lol |
# |
Jul 12th 2021, 17:13 |
kevin.pfeifer |
if i had a "better" github name I would do the same :,) |
# |
Jul 12th 2021, 17:04 |
tyler.adam.lazenby |
nevermind, it was because I had made the action 'add-user' instead of 'addUser' |
# |
Jul 12th 2021, 16:40 |
tyler.adam.lazenby |
how do I force the router to use that scope when I am trying to create links |
# |
Jul 12th 2021, 16:39 |
slackebot2 |
'newUser']); // This one works but isn't automatically used by the link generator $this->Html->link() or by the Router::url() });``` |
# |
Jul 12th 2021, 16:39 |
tyler.adam.lazenby |
Question. I have a scope that I am trying to create. I have two actions so far. The problem is that only one of them gets automatically generated when using a link command. ```$builder->scope('/account', function (RouteBuilder $builder) { $builder->connect('/', ['controller' => 'Accounts', 'action' => 'userIndex']); // this one works $builder->connect('/new-user', ['controller' => 'Accounts', 'action' => |
# |
Jul 12th 2021, 16:15 |
richard |
@ndm thanks will look into it |
# |
Jul 12th 2021, 16:08 |
tyler.adam.lazenby |
Sorry for any confusing changing my display name may cause right now, but I thought that I should just change my display name to match my github account. |
# |
Jul 12th 2021, 16:06 |
ndm |
@richard Depends on your needs and your environment I guess... you may want to give a tool like percona monitoring a try. |
# |
Jul 12th 2021, 16:05 |
tyler.adam.lazenby |
oh sorry I just googled that. That isn't a chat acronym that I have run across. I must be getting old. |
# |
Jul 12th 2021, 16:05 |
tyler.adam.lazenby |
afaik? |
# |
Jul 12th 2021, 16:04 |
dereuromark |
Submit was never intended for HTML afaik |
# |
Jul 12th 2021, 16:04 |
tyler.adam.lazenby |
That is my work around for now |
# |
Jul 12th 2021, 16:04 |
dereuromark |
Use button() instead. |