# |
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 |
# |
Jun 24th 2021, 05:43 |
alamnaryab |
I am making tables named classes and sessions entity class name will be `Class` and `Session` which are reserved works how should I handle it? |
# |
Jun 24th 2021, 05:39 |
alamnaryab |
good morning all |
# |
Jun 24th 2021, 04:23 |
divyesh.prajapati |
What is main agenda CakeFest? How can we attend this? |
# |
Jun 23rd 2021, 23:07 |
ljolley |
That's what I was looking for @kevin.pfeifer. I'll fool around with it. Thanks! |
# |
Jun 23rd 2021, 23:05 |
kevin.pfeifer |
Or you use mailer profiles which can be set when creating the mailer object https://book.cakephp.org/4/en/core-libraries/email.html#configuration Mailer profiles are defined in your config/app.php https://github.com/cakephp/app/blob/master/config/app.php#L257 |
# |
Jun 23rd 2021, 23:03 |
dereuromark |
You can also use a custom Message, like Tools plugin one ( https://github.com/dereuromark/cakephp-tools/blob/master/src/Mailer/Message.php#L41 ) which sets defaults here based on app config. |
# |
Jun 23rd 2021, 23:00 |
greg138 |
Use a custom transport that extends the standard one and just calls `setFrom` with your default value, then calls the parent implementation? |
# |
Jun 23rd 2021, 22:58 |
ljolley |
Does anyone know if there is a way to define the `setFrom` for a `Cake\Mailer\Mailer` in the `EmailTransport` defined in `/config/app.php` so it doesn't have to be set every time an email is generated? |
# |
Jun 23rd 2021, 22:55 |
sebastiansperandio093 |
thanks! I supposed something like that. I was looking for some ideas. Thanks Kevin |