# |
Jun 24th 2021, 22:47 |
ricmelero |
Sorry, RouteName::login is ['_name' => 'login'] |
# |
Jun 24th 2021, 22:47 |
ricmelero |
I'm having a weird issue with routes, that fails the second time I build the same url, in this case a named route: ```$loginUrl = Router::url(RouteNames::login); $loginUrl = Router::url(RouteNames::login);``` The first call works ok, building login url, but second fails |
# |
Jun 24th 2021, 21:10 |
marius.treu |
my current approach is with amphp executing the resulting SQL genereated by an cakephp query |
# |
Jun 24th 2021, 21:10 |
marius.treu |
hi all, is there a way to create async queries with the cakephp ORM? |
# |
Jun 24th 2021, 20:12 |
rightscoreanalysis |
my bad, I frogot to prefix themodel with the plugin name |
# |
Jun 24th 2021, 20:02 |
rightscoreanalysis |
anyone able to help with a cake2 question, in my Api model: public $useTable = false; in another model I have: ClassRegistry::init('Api'); but I get: *Error:* Table _apis_ for model _Api_ was not found in datasource _default_. |
# |
Jun 24th 2021, 16:37 |
richard |
no worries, i always thought it was weird too ;) |
# |
Jun 24th 2021, 16:36 |
kaliel |
thank you <3 |
# |
Jun 24th 2021, 16:36 |
kaliel |
@richard oh my god it works, kind of weird |
# |
Jun 24th 2021, 16:35 |
richard |
@kaliel yes |
# |
Jun 24th 2021, 16:35 |
richard |
think it’s ‘_method’ |
# |
Jun 24th 2021, 16:35 |
kaliel |
you mean in Router::url ? |
# |
Jun 24th 2021, 16:35 |
richard |
and you have to if you limit it like that i believe |
# |
Jun 24th 2021, 16:35 |
richard |
@kaliel you can specify the method in the route |
# |
Jun 24th 2021, 16:32 |
kaliel |
```$url = Router::url(['prefix' => 'Api', 'controller' => 'Payment', 'action' => 'notify'], true); // gives a MissingRouteException``` |
# |
Jun 24th 2021, 16:31 |
kaliel |
Hi everyone, any clue on why a route which only accept POST method, is not found by Router;;url() ? ``` $builder->connect('/payment/notify', ['controller' => 'Payment', 'action' => 'notify']) ->setMethods(['POST']);``` |
# |
Jun 24th 2021, 15:11 |
admad |
`contain('Related' => function ($q) { //modify query })` |
# |
Jun 24th 2021, 09:06 |
conehead |
@val I added a Rule "IsNullOrUnique" for that |
# |
Jun 24th 2021, 09:03 |
val |
Hi, is there a way to use `$rules->isUnique()` in 3.x but to ignore this rule if the field value that should be validated is null? |
# |
Jun 24th 2021, 08:47 |
conehead |
Yes, that does work. But I think it would be not so good to catch the event every time something is saved and then 99.9% of the time just do nothing :P I guess I will just go with it by triggering my own event |
# |
Jun 24th 2021, 08:45 |
kevin.pfeifer |
Model.beforeSave here: https://github.com/cakephp/cakephp/blob/master/src/ORM/Table.php#L1936 |
# |
Jun 24th 2021, 08:44 |
kevin.pfeifer |
e.g. the global Model.afterSave event is being triggered here https://github.com/cakephp/cakephp/blob/master/src/ORM/Table.php#L2009 |
# |
Jun 24th 2021, 08:43 |
conehead |
Like the first sentence of the Event System says: "Creating maintainable applications is both a science and an art. It is well-known that a key for having good quality code is making your objects loosely coupled and strongly cohesive at the same time. Cohesion means that all methods and properties for a class are strongly related to the class itself and it is not trying to do the job other objects should be doing, while loosely |
# |
Jun 24th 2021, 08:43 |
slackebot |
coupling is the measure of how little a class is “wired” to external objects, and how much that class is depending on them." |
# |
Jun 24th 2021, 08:38 |
conehead |
@erwane What is weird about it? I think it is even cleaner to seperate code like this. Especially if multiple models are involved @kevin.pfeifer Yes thanks, that is what I think I will do (or what I am already doing). Was just wondering if these events were triggered automatically. I just don't see code of updating other data or sending mails in my table. Especially by putting it in an EventListener it makes it way easier to |
# |
Jun 24th 2021, 08:38 |
slackebot |
test it |
# |
Jun 24th 2021, 08:36 |
kevin.pfeifer |
but I can't tell you the performance impact of one over the other |
# |
Jun 24th 2021, 08:35 |
kevin.pfeifer |
but sure, you could dispatch an event in the afterSave function of your UsersTable and then put your logic in the listener for `Model.Users.afterSave` |
# |
Jun 24th 2021, 08:30 |
kevin.pfeifer |
look at the last code example in this section https://book.cakephp.org/4/en/core-libraries/events.html#registering-anonymous-listeners |
# |
Jun 24th 2021, 08:30 |
erwane |
But it's ... weird ... |
# |
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 |
``` |
# |
Jun 24th 2021, 07:51 |
romuald |
```php |
# |
Jun 24th 2021, 07:51 |
romuald |
/ Template/Products/index.ctp |
# |
Jun 24th 2021, 07:51 |
romuald |
$products = $this->paginate($products); |
# |
Jun 24th 2021, 07:51 |
romuald |
$this->set(compact('products')); |
# |
Jun 24th 2021, 07:51 |
romuald |
]); |
# |
Jun 24th 2021, 07:51 |
romuald |
])->where(['Alerts.active' => true]); |
# |
Jun 24th 2021, 07:51 |
romuald |
} |
# |
Jun 24th 2021, 07:51 |
romuald |
'Alerts.active', |
# |
Jun 24th 2021, 07:51 |
romuald |
'alerts_total' => $q->func()->count('Alerts.id') |
# |
Jun 24th 2021, 07:51 |
romuald |
'Alerts' => function($q) { |
# |
Jun 24th 2021, 07:51 |
romuald |
return $q->select([ |
# |
Jun 24th 2021, 07:51 |
romuald |
'Alerts.product_id', |
# |
Jun 24th 2021, 07:51 |
romuald |
$products->find()->contain([ |
# |
Jun 24th 2021, 07:51 |
romuald |
Hi all !! What I missed here to have a "count field" ordered with Paginator ? |
# |
Jun 24th 2021, 07:51 |
romuald |
```php |
# |
Jun 24th 2021, 07:51 |
romuald |
/ Controller/ProductsController.php |
# |
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 |
# |
Jun 23rd 2021, 21:26 |
tyler.adam.lazenby |
Right, and I think just using the `getData()` method will work fine it is a json body that gets sent over. |
# |
Jun 23rd 2021, 21:25 |
kevin.pfeifer |
```$this->request->getParsedBody();``` will give you the json directly if you desire that more |
# |
Jun 23rd 2021, 21:24 |
tyler.adam.lazenby |
thank you!!!!!!!! |
# |
Jun 23rd 2021, 21:24 |
kevin.pfeifer |
with `$this->request->getBody()` you get a PhpInputStream. If you want the unparsed body, you need to call ```$this->request->getBody()->getContents()``` |
# |
Jun 23rd 2021, 21:19 |
tyler.adam.lazenby |
thank you so much |
# |
Jun 23rd 2021, 21:19 |
kevin.pfeifer |
let me check with one of my json post data |
# |
Jun 23rd 2021, 21:16 |
tyler.adam.lazenby |
and the stream interface... has issues |
# |
Jun 23rd 2021, 21:16 |
tyler.adam.lazenby |
I need the string version of the body |
# |
Jun 23rd 2021, 21:14 |
kevin.pfeifer |
or `$this->request->getParsedBody();` if you want the parsed body :) See also https://github.com/cakephp/cakephp/blob/master/src/Http/ServerRequest.php#L1271 |
# |
Jun 23rd 2021, 21:13 |
kevin.pfeifer |
you can also check `$this->request->getBody();` |
# |
Jun 23rd 2021, 21:12 |
tyler.adam.lazenby |
just wanna do it the cake way as much as possible though |
# |
Jun 23rd 2021, 21:12 |
tyler.adam.lazenby |
I just know that the command above is what works on my old source code |
# |
Jun 23rd 2021, 21:11 |
tyler.adam.lazenby |
I wasn't sure if it would |
# |
Jun 23rd 2021, 21:11 |
kevin.pfeifer |
so does `$this->request->getData();` not return what you expect? |
# |
Jun 23rd 2021, 21:07 |
tyler.adam.lazenby |
basically I need the equivalent of `file_get_contents('php://input')` |
# |
Jun 23rd 2021, 21:06 |
tyler.adam.lazenby |
before I get any further, I would like to ask what you would say to do when I am going to need the request body to be able to hash and see if the signature matches? |
# |
Jun 23rd 2021, 20:17 |
tyler.adam.lazenby |
I know all about that |
# |
Jun 23rd 2021, 20:17 |
steinkel |
but for regular forms you have this one and his cousing ```$this->enableCsrfToken();``` |
# |
Jun 23rd 2021, 20:17 |
tyler.adam.lazenby |
I was avoiding using the enablecsrf() |
# |
Jun 23rd 2021, 20:16 |
tyler.adam.lazenby |
yeah] |