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
1 answer
CakePHP migration re-organising column order
I have added new column using migrations.
This is my new added field
$table->addColumn('lastname', 'string', [
'default' => null,
'limit' => 255,
'null' => false,
]);
This column added after modified field. I…

Niloy Rony
- 602
- 1
- 8
- 23
1
vote
1 answer
Cakephp4, detect if upload field present
When migrating from 3.9, I get an error when trying to check if a file has been uploaded using the upload behaviour.
if ($this->request->getData('import.name')) {
Cannot use object of type Laminas\Diactoros\UploadedFile as array
How should I…

Will
- 4,498
- 2
- 38
- 65
1
vote
3 answers
CakePHP 4 Authentication Redirect after successful login
I'm implementing Authentication in a new CakePHP 4 app (per the CMS Tutorial)
I have had to change the getAuthenticationService method in Application.php to be:
'unauthenticatedRedirect' => \Cake\Routing\Router::url('/users/login'),
and
'loginUrl'…

dividedbyzero
- 181
- 2
- 13
1
vote
1 answer
CakePHP 4 - bake won't let me use a different database connection to 'default'
CakePHP 4.0.8
In my config/app_local.php I have 2 different databases defined:
'Datasources' => [
'default' => [
'host' => 'localhost',
'username' => '***',
'password' => '***',
'database' => 'db1',
'url'…

Andy
- 5,142
- 11
- 58
- 131
1
vote
2 answers
CakePHP 4 CMS Authentication Tutorial redirection to login not working (subfolder ignored)
Im trying to implement an authentication according to the offical CMS Tutorial: https://book.cakephp.org/4/en/tutorials-and-examples/cms/authentication.html#adding-login
But the Redirection implemented here:
public function…

mjd
- 109
- 1
- 1
- 11
1
vote
1 answer
CakePHP 4.x - How to Bake Twig Templates?
Is it possible to use Bake to generate basic CRUD views formatted in the Twig standard? I'm converting my templates generated by Bake manually and it's a lot of work. I'm using CakePHP 4.0.3 in my project and the "TwigView plugin" from…

godzill4
- 25
- 5
1
vote
1 answer
CakePHP - Hotw to Generate Select Field with Mutiple Attribute using FormHelper
I need to find a way to set the default values of a select-type field which has the multiple attribute.
Here is the data sent to the view through the controller:
$categories = [
['id' => 1, 'description' => 'Hardware'],
['id' => 2,…

godzill4
- 25
- 5
1
vote
1 answer
CakePHP 4.0 - how do I create and show validation errors against fields?
I'm using CakePHP 4.0, and creating a user registration page. I've set up some validation rules, which are returning errors when expected, but I can't figure out how to get them to show against the appropriate fields in the form. In v3.0 this seemed…

Sharon
- 3,471
- 13
- 60
- 93
1
vote
1 answer
How do I get my Authenticated user info? As Id and such?
I'm new at the latest cakephp versions and hadn't used the Authentication Component until now. I'm trying to validate a user being an admin but can't find how to get the user id to get it, nor how to get the identifier.…

SrQ
- 106
- 7
1
vote
1 answer
cakephp 4 - authentication 2 - How to display message when not identified
I use authentication (2) plugin with cakephp4.
I have set :
'unauthenticatedRedirect' => '/users/login',
in order to redirect requests that need authentication. It works fine.
But I'd like to add a message, a flash message for example,…

dype
- 500
- 1
- 4
- 15
1
vote
0 answers
Why is the code that enables the .env file to be loaded located in bootstrap.php?
I'm using CakePHP 4 and I'm setting up my development environment. To enable the use of the .env file I uncomment the block found in bootstrap.php, as explained in the Cookbook:
// if (!env('APP_NAME') && file_exists(CONFIG . '.env')) {
// …

FrankSunnyman
- 241
- 3
- 13
1
vote
0 answers
my entity file is not being included in the cakephp. Can someone help me?
I was trying to hash the password but it turns out that my entity file is not being included in the cakephp. Can someone help me why it is happening ???
When i run debug(get_included_file()); it does not show my User.php entity file.
and my…

Shiv Shankar Prasad
- 145
- 2
- 15
1
vote
1 answer
Conflict error during CakePHP 3.8.10 to 4.x upgrade
I want to upgrade the CakePHP framework behind our project. Currently we are using the 3.8.10 version.
I did all the steps to complete the process described here:
https://book.cakephp.org/4/en/appendices/4-0-upgrade-guide.html
(I have no, errors,…

Sanyos
- 41
- 3
1
vote
1 answer
cakephp 4 Testing Actions That Require Authentication
Testing actions that require authentication do not work as describe cakephp manual.
I found this solution, is it the correct one ?
use App\Model\Entity\User;
...
public function testLogout()
{
$user=new User();
$user->id=1;
…

dype
- 500
- 1
- 4
- 15
1
vote
1 answer
How to use route elements instead of query string arguments for pagination in CakePHP 4.x?
My website's pagination urls worked like this, but stopped working when i upgraded to 4.x - for example: 1st page: mywebsite.com/new - 2nd page: mywebsite.com/new/page/2, etc. I did that with the following code:
//routes.php …

ndru
- 83
- 1
- 10