# |
Sep 2nd 2019, 10:28 |
challgren |
It would be in your beforeSave/beforeFind |
# |
Sep 2nd 2019, 10:27 |
neon1024 |
I wanted `$this->_footprint->get('id')` or similar |
# |
Sep 2nd 2019, 10:27 |
neon1024 |
I am using Duplicatable in the Table class, and need the current users id |
# |
Sep 2nd 2019, 10:27 |
neon1024 |
> This plugin allows you to pass the currently logged in user to the model layer of a CakePHP 3 application. |
# |
Sep 2nd 2019, 10:27 |
neon1024 |
Which kinda makes this false |
# |
Sep 2nd 2019, 10:27 |
challgren |
Why? |
# |
Sep 2nd 2019, 10:27 |
neon1024 |
Right, so it’s no good for what I need. That’s a shame |
# |
Sep 2nd 2019, 10:26 |
challgren |
So yep when calling save it will inject the current user in the save `$options` |
# |
Sep 2nd 2019, 10:25 |
challgren |
Well and figuring out how it does it |
# |
Sep 2nd 2019, 10:25 |
challgren |
Yep |
# |
Sep 2nd 2019, 10:25 |
neon1024 |
Are you searching the plugin for `_footprint` ? ;) |
# |
Sep 2nd 2019, 10:24 |
challgren |
https://github.com/UseMuffin/Footprint/blob/master/src/Model/Behavior/FootprintBehavior.php#L29 |
# |
Sep 2nd 2019, 10:23 |
challgren |
https://github.com/UseMuffin/Footprint/blob/master/src/Event/FootprintListener.php#L82 |
# |
Sep 2nd 2019, 10:22 |
challgren |
https://github.com/UseMuffin/Footprint/blob/master/src/Event/FootprintListener.php#L25 |
# |
Sep 2nd 2019, 10:22 |
neon1024 |
I’ll check the behaviour as that must use it to populate the created_by field |
# |
Sep 2nd 2019, 10:21 |
challgren |
maybe `$table->save($entity, ['_footprint' => $options']);` |
# |
Sep 2nd 2019, 10:20 |
neon1024 |
No mention of which `$options` or where |
# |
Sep 2nd 2019, 10:20 |
neon1024 |
> in the _footprint key of $options |
# |
Sep 2nd 2019, 10:20 |
neon1024 |
As it says |
# |
Sep 2nd 2019, 10:20 |
challgren |
Its in the FootprintAwareTrait I recall |
# |
Sep 2nd 2019, 10:19 |
neon1024 |
Is it this? `$this->request->getAttribute('identity')` |
# |
Sep 2nd 2019, 10:19 |
neon1024 |
Bit of a stupid question, but the usemuffin/footprint readme, doesn’t tell me how to get the user data in the model |
# |
Sep 2nd 2019, 10:15 |
neon1024 |
Easier to test with a concrete method implementation too :slightly_smiling_face: |
# |
Sep 2nd 2019, 10:08 |
dereuromark |
Jep, this is another reason why actual methods on the entity can make sense if you always want to call it manually :slightly_smiling_face: in that case the methods dont have a prefix `_get` |
# |
Sep 2nd 2019, 10:06 |
neon1024 |
Uses the magic method `__call()` I’d guess |
# |
Sep 2nd 2019, 10:00 |
mehov |
wow so unless I call `$entity->some_calculation`, `_getSomeCalculation()` won't be executed? how is that done on underlying PHP level? not asking you to explain much, just what to google |
# |
Sep 2nd 2019, 09:53 |
dereuromark |
Yeah, I am for basic stuff only, for those and other reasons. Everything else move out of such a basic DTO kind of structure :slightly_smiling_face: |
# |
Sep 2nd 2019, 09:53 |
dereuromark |
and as long as you dont expose them - as I wrote about - then toArray() etc also wouldnt call them either. |
# |
Sep 2nd 2019, 09:53 |
dereuromark |
only calculated if called :slightly_smiling_face: |
# |
Sep 2nd 2019, 09:45 |
slackebot2 |
agree it's not as elegant as building on top of existing virtual fields functionality, I won't have it run everywhere even if I don't need it, unless I explicitly need it. Is there any way to control where shouldn't the virtual fields be calculated? Or should I keep some complex calculation (if any) still in my custom methods, and move only basic stuff to virtual fields (like full name concatenation from the cookbook)? |
# |
Sep 2nd 2019, 09:45 |
mehov |
https://cakesf.slack.com/archives/C053DPNGT/p1567414394455200 @dereuromark thanks for the tip, I was about to convert the entity to use these, but got thinking. If I define a bunch of `_getSomeCalculation()` methods on my entity, are those going to be called on every initialisation of that entity from now on? Regardless of whether I need that calculation in a given controller/model If I have my custom `calculateSomething()` method, while I |
# |
Sep 2nd 2019, 09:38 |
alexdd55976 |
only select on fields that are needed is a very good advice. |
# |
Sep 2nd 2019, 09:37 |
challgren |
Unless you need entities |
# |
Sep 2nd 2019, 09:36 |
challgren |
Also maybe disableHydration() |
# |
Sep 2nd 2019, 09:36 |
slackebot2 |
cake would just render all the fields from all the tables involved into the query and it got huge because of that. your case may be different, just saying |
# |
Sep 2nd 2019, 09:36 |
mehov |
@turkles there's a good piece of advice right above, make sure you get only the data you need. do not contain what you don't need. sometimes looking at an actual SQL in the debug panel helps (if you're in console, reuse the model method that retrieves data in some controller just to see the SQL) also, if I remember it right, I think I had a slow query which I was able to speed up a bit by explicitly defining which fields to select; otherwise |
# |
Sep 2nd 2019, 09:30 |
turkles |
so at the moment I have a query limit 100, and then do ->each(), then saveMany. If I wrap that in a loop (and iterate query), it should behave? I must have a leak somewhere O_o |
# |
Sep 2nd 2019, 09:27 |
alexdd55976 |
how can i tell authentication plugin to redirect to `/user/login` if user is not authenticated |
# |
Sep 2nd 2019, 09:25 |
challgren |
@turkles also contain and/or retrieve only the fields you need |
# |
Sep 2nd 2019, 09:19 |
dereuromark |
read in chunks/parts, unset() what you dont need in those loops. |
# |
Sep 2nd 2019, 09:15 |
turkles |
I need to go through 2m records, and I keep running out of space, can I clean out memory somehow in my shell? |