Questions about 4.x branch of the CakePHP MVC framework. Use this tag in combination with the general [cakephp] tag. If your question applies to CakePHP more generally, use only the [cakephp] tag.
Questions tagged [cakephp-4.x]
511 questions
1
vote
0 answers
Cakephp how to redirect from beforeRender method in AppController?
User case I'm trying to do, if a user not submit his company details always redirect user to company page.
In appController I have written like below beforeRender method
public function beforeRender(\Cake\Event\EventInterface $event) {
…

Niloy Rony
- 602
- 1
- 8
- 23
1
vote
0 answers
How to paginate related articles in cakephp 4
I am playing with cakephp 4. I have three table. This is belongsToMany Relation.
1. me_article
me_article.id,me_article.slug,me_article.title
'foreignKey' => 'me_category_id',
'targetForeignKey' => 'me_artcle_id',
2. me_category
…

Achmad Muqorobin
- 11
- 2
1
vote
1 answer
Cakephp how can I fetch same table association data
I have a database table called miles, miles data looks like after fetch and return in Json.
"userMiles": [
{
"id": 278,
"gain_miles": 0.02,
"start_time": "2022-07-06T15:40:47+09:00",
"end_time":…

Abu Sayed
- 75
- 7
1
vote
1 answer
How to compare Query conditions from a BelongsToMany association in CakePHP 4.x?
I have a working Posts, Categories and Tags relationship. (Posts BelongsTo Categories and BelongsToMany Tags.) They work just fine at my view and index actions with no issue.
Now, for a simple "search" functionality I'm working with the Query…

Damian Fraustro
- 51
- 8
1
vote
0 answers
Cakephp 4 - Save with Associations
I am having problems with saving data with associated. The problem is that i'm do thing on AfterSave and the associations are triggering the AfterSave before the principal entity($toSave). This is normal?
It's like first save the associations then…

TacticJuls
- 304
- 1
- 8
1
vote
1 answer
CakePHP 4 - setting request data
We have a CakePHP 3.x app which we've updated to the latest CakePHP 4.x. As part of this work we've also changed from PHP 7 to PHP 8.
Whilst testing the app we noticed a feature that had stopped working.
The app is a searchable database and is…

Andy
- 5,142
- 11
- 58
- 131
1
vote
2 answers
CakePHP 4 - how do you get the ID of the currently logged in user with the new Authentication component?
In CakePHP - prior to version 4.x - it had a simple Auth component which dealt with setting up authentication/authorization and made it very easy to do things like get a logged-in user ID with one line of code.
In 4.x the Auth component has been…

Andy
- 5,142
- 11
- 58
- 131
1
vote
1 answer
MissingTemplateException::$file must be string (as in class Exception)
I am using PHP8 and the project is in Cakephp4.
For any single notice or warning, it gives Template Exception Error and breaks the project.
Fatal error: Type of Cake\View\Exception\MissingTemplateException::$file must be string (as in class…

Alisa
- 313
- 5
- 20
1
vote
0 answers
Mailer issue with SMTP in CakePhp 4
I am using CakePHP 4.2.8 and trying to send email via smtp, but i am getting time out error and used same email account in other php app (using phpmailer ) and its working fine.
Here is my code.
use Cake\Mailer\Mailer;
use…

Yogesh Saroya
- 1,401
- 5
- 23
- 52
1
vote
1 answer
Aligning radio button's vertically with CakePHP 4
My issue
I am using the cakephp 4 FormHelper to create some radio buttons on my page. It will create the radio buttons, however it will display them horizontally like in the image below but I want them to be displayed vertically.
My…

Paul
- 67
- 6
1
vote
1 answer
CakePHP 4 - How do I create a simple proof of concept REST API?
How do I get a simple proof-of-concept REST API working in CakePHP 4?
I have followed the guides in CakePHP's cookbook here and here
Currently my routes.php file contains the following (with comments removed):

wmdvanzyl
- 352
- 2
- 5
- 17
1
vote
1 answer
CakePHP4: Convert or cast Cake\ORM\Entity to actual entity for type hinting
Let's say I have a method that is expecting an Invoice entity as a parameter. So I add the type hint Invoice like so:
public function doThatThing (Invoice $invoiceEntity)
{
// ... operate on $invoiceEntity
}
Unfortunately, when I pass the…

MM.
- 1,966
- 4
- 20
- 24
1
vote
1 answer
CakePHP 4 Bake Custom TemplateCommand in Plugin
I cannot seem to override TemplateCommand from my plugin.
Original TemplateCommand located here: vendor/cakephp/bake/src/Command/TemplateCommand.php
namespace Bake\Command;
...
class TemplateCommand extends BakeCommand
{...}
I stored mine here:…

TechFanDan
- 3,329
- 6
- 46
- 89
1
vote
1 answer
deleteAll with conditions and a delete limit
CakePHP Version: 4.2.6
Xampp:
Apache/2.4.51 (Win64) OpenSSL/1.1.1l PHP/8.0.11
Server version: 10.4.21-MariaDB - mariadb.org binary distribution
PHP version: 8.0.11
Introduction
I'm trying to construct a deleteAll query with the order by and limit…

Zenzs
- 138
- 13
1
vote
1 answer
cakePHP 4 how to change session.cookie_lifetime
I have time in seconds when the session should end. If the user has not selected the checkbox "remember_me" - the session will last 2 hours. When the checkbox is selected - should last - 48 hours. I have a loginСontroller, where I react - to the…

Andrii Tomkiv
- 13
- 3