Log message #4266337

# At Username Text
# Jun 24th 2021, 08:29 erwane If you want events in another file, you have to trigger you own events name. You have to do ```public function afterSave($event) { $this->dispatchEvent('Model.Users.afterSave', ...) } ```
# Jun 24th 2021, 08:29 conehead Or I would catch 'Model.afterSave' and then check if its the correct Table...but probably that would slow things down a lot if I check it after every save
# Jun 24th 2021, 08:27 conehead Yes, but in that case I would have to dispatch a new event in the afterSave method, correct?
# Jun 24th 2021, 08:26 kevin.pfeifer usually you are fine adding these events to your config/bootstrap.php (or require a events.php in the config/bootstrap.php which adds those listeners)
# Jun 24th 2021, 08:25 kevin.pfeifer well ok, the afterSave() function in the UsersTable is just a preconfigured function called on that event you want. But if you want that to be present elsewhere you just need to be sure, that your listener is set before the actuall event is being triggered
# Jun 24th 2021, 08:23 conehead @kevin.pfeifer not sure...should it? In my opinion it is cleaner to seperate it. I do not want to blow up the UsersTable
# Jun 24th 2021, 08:22 conehead Was hoping I could do something like this in the AppController: ``` EventManager::instance()->on( 'Model.Users.afterSave', function ($event) { debug($event); die(); } );```
# Jun 24th 2021, 08:21 kevin.pfeifer well shouldn't that code be present in the `afterSave()` function present in the UsersTable?
# Jun 24th 2021, 08:20 kevin.pfeifer @romuald see https://stackoverflow.com/questions/58327906/cakephp-pagination-how-do-i-sort-by-the-count-of-a-contained-model
# Jun 24th 2021, 08:20 conehead On global level I want to react to a specific Table event. Lets say I want to add an Listener to 'Model.Users.afterSave' to send new Users an E-Mail
# Jun 24th 2021, 08:19 erwane you can listen Global events but Model.afterSave will be global
# Jun 24th 2021, 08:19 kevin.pfeifer well you definitely could rename and manually connect tables and entities yourself but in my opinion this just increases the work needed to be done and future errors to pop up I would always stick to https://book.cakephp.org/4/en/intro/conventions.html and prevent as many reserved words (wherever they are present - SQL, PHP or wherever) as possible
# Jun 24th 2021, 08:18 erwane Events are attached to an instance. So, if you are doing actions on UsersTable, the Model.afterSave will call usersTable::afterSave
# Jun 24th 2021, 08:17 conehead Good morning everyone. Anyone using events a lot? I was just wondering...can I just listen for events for a specific table? Aren't they called automatically? I know they trigger for example 'Model.afterSave', but they do not trigger spefic events like 'Model.Users.afterSave'? Do I have to trigger them manually?
# Jun 24th 2021, 08:16 erwane and shool_groupes ?
# Jun 24th 2021, 08:16 erwane sessions can be workshops ?
# Jun 24th 2021, 08:15 alamnaryab I can you any name, but wanted to learn how experts do it. I like the prefixed version `school_classes` `academic_sessions`
# Jun 24th 2021, 08:12 erwane @alamnaryab you can't use another approching names ?
# Jun 24th 2021, 08:12 kevin.pfeifer @alamnaryab I would rename the table to something like `custom_classes` or `project_classes` or something that is related to what this table actually does. Then you have a valid name and everything should get auto-generated with the bake command
# Jun 24th 2021, 07:53 romuald Uploaded file: https://uploads.kiwiirc.com/files/7c36d290f9028c62f3e120f811158060/pasted.txt
# Jun 24th 2021, 07:52 alamnaryab what is best practice in this scenario? should I name tables as `clases` instead of `classes` but then label will be wrong
# Jun 24th 2021, 07:51 romuald ```
# Jun 24th 2021, 07:51 romuald <th scope="col"><?= $this->Paginator->sort('Alerts.alerts_total', "Total alerts") ?></th>
# Jun 24th 2021, 07:51 romuald / Template/Products/index.ctp
# Jun 24th 2021, 07:51 romuald ```php
# Jun 24th 2021, 07:51 romuald ```
# Jun 24th 2021, 07:51 romuald $this->set(compact('products'));
# Jun 24th 2021, 07:51 romuald $products = $this->paginate($products);
# Jun 24th 2021, 07:51 romuald ]);
# Jun 24th 2021, 07:51 romuald }
# Jun 24th 2021, 07:51 romuald ])->where(['Alerts.active' => true]);
# Jun 24th 2021, 07:51 romuald 'alerts_total' => $q->func()->count('Alerts.id')
# Jun 24th 2021, 07:51 romuald 'Alerts.active',
# Jun 24th 2021, 07:51 romuald 'Alerts.product_id',
# Jun 24th 2021, 07:51 romuald return $q->select([
# Jun 24th 2021, 07:51 romuald 'Alerts' => function($q) {
# Jun 24th 2021, 07:51 romuald $products->find()->contain([
# Jun 24th 2021, 07:51 romuald / Controller/ProductsController.php
# Jun 24th 2021, 07:51 romuald ```php
# Jun 24th 2021, 07:51 romuald Hi all !! What I missed here to have a "count field" ordered with Paginator ?
# Jun 24th 2021, 06:10 erwane You don't have another name for this entities ? Your Table can use the entity you want (set entityClasssName in your model) but with this class and session reserverd words, it will be a problem in all your project, every time