Kim Stacks
Kim Stacks

Reputation: 10812

Cake 3.x How to use database sessions with a controller named SessionsController?

Cake Version 3.1.2

What I did:

  1. Run the following query in MySQL database:

    CREATE TABLE `sessions` (
      `id` varchar(255) NOT NULL DEFAULT '',
      `data` BLOB, -- or BYTEA for PostgreSQL
      `expires` int(11) DEFAULT NULL,
       PRIMARY KEY (`id`)
    );
    
  2. Change app.php

    'Session' => [
        'defaults' => 'database',
    ],
    

What I wanted:

To have a SessionsController.php

so I can have :

Questions in my mind:

  1. Do I actually bake Session Entity and Table?
  2. Do I actually bake Session Controller?
  3. Is it even possible for me to have SessionsController even when I don't use database to handle my Session? How do I bake such a Controller that does not have a default Entity or Table?

Upvotes: 7

Views: 723

Answers (1)

chrisShick
chrisShick

Reputation: 1096

Most of the questions you have are answered in the CakePHP Book. The answers to your questions are:

  1. Do I actually bake Session Entity and Table?
  2. Do I actually bake Session Controller?

    A: No, you don't HAVE to bake anything. You can write all the code by hand. Although, I recommend baking to set up the skeleton of the classes.

  3. Is it even possible for me to have SessionsController even when I don't use database to handle my Session?

    A: Yes, you can name your controllers anything you want as long as you follow the naming conventions.

  4. How do I bake such a Controller that does not have a default Entity or Table?

    A: You just bake it. You don't have to use models, default or otherwise, in your controllers.

Upvotes: 2

Related Questions