Cake Software Foundation, Inc. - Latest posts https://discourse.cakephp.org Latest posts Authentication with CakePHP 5 v4 is what you want to use right now if you start a fresh new app

]]>
https://discourse.cakephp.org/t/authentication-with-cakephp-5/12814#post_2 Mon, 16 Mar 2026 15:26:43 +0000 discourse.cakephp.org-post-31597
Authentication with CakePHP 5 Which version of authentication runs perfect with Cake 5.2.12?

Thanks for advice!

]]>
https://discourse.cakephp.org/t/authentication-with-cakephp-5/12814#post_1 Mon, 16 Mar 2026 12:31:20 +0000 discourse.cakephp.org-post-31596
Paginator Error You may write foreach($news as $item):

]]>
https://discourse.cakephp.org/t/paginator-error/12806#post_3 Wed, 11 Mar 2026 14:25:28 +0000 discourse.cakephp.org-post-31593
Friendsofcake/search plugin 6.2 - hide URL search parameters Thanks for the advice, which pointed me toward a strategy that uses encrypted cookies. I solved the problem, thank you very much.

]]>
https://discourse.cakephp.org/t/friendsofcake-search-plugin-6-2-hide-url-search-parameters/12811#post_8 Tue, 10 Mar 2026 14:25:17 +0000 discourse.cakephp.org-post-31592
Friendsofcake/search plugin 6.2 - hide URL search parameters I still am not understanding the use case where “process the data securely” and “display the parameters in the URL” are mutually incompatible things. If a user can see certain data, then it shouldn’t matter if it’s in the URL or not. If they can’t see it, they should not be able to see it anywhere, URL or otherwise.

]]>
https://discourse.cakephp.org/t/friendsofcake-search-plugin-6-2-hide-url-search-parameters/12811#post_7 Tue, 10 Mar 2026 14:13:18 +0000 discourse.cakephp.org-post-31591
Friendsofcake/search plugin 6.2 - hide URL search parameters Yes, perhaps I phrased the question incorrectly. My goal is to not display the parameters in the URL, but at the same time, I’m aware that the best solution would be to pass the data as securely as possible.

]]>
https://discourse.cakephp.org/t/friendsofcake-search-plugin-6-2-hide-url-search-parameters/12811#post_6 Mon, 09 Mar 2026 15:41:54 +0000 discourse.cakephp.org-post-31590
Friendsofcake/search plugin 6.2 - hide URL search parameters You can always proxy them away using a “hash map”.
So the exact conditions are hidden behind a ?q=xyz (can be UUID or other random values)
And xyz string internally resolves back into the array of conditions for example.
If dynamic, this likely needs to be a DB table for lookup (from json stored data somewhere).
If you only have a few options, this could be a hardcoded map.

Thats not transparent of course, but thats the goal here clearly :slight_smile:

Fun fact: The new Cake53 pagination system I built also does allow similar grouping and sorting for general cases, you can add inifite things within one “x asc/desc” and make those not exposed.

]]>
https://discourse.cakephp.org/t/friendsofcake-search-plugin-6-2-hide-url-search-parameters/12811#post_5 Mon, 09 Mar 2026 15:24:05 +0000 discourse.cakephp.org-post-31589
Friendsofcake/search plugin 6.2 - hide URL search parameters But how does not including the search parameters in the URL make anything more secure or confidential? I’m not trying to be difficult, I’m trying to understand your problem, so that a useful solution might be suggested.

]]>
https://discourse.cakephp.org/t/friendsofcake-search-plugin-6-2-hide-url-search-parameters/12811#post_4 Mon, 09 Mar 2026 15:12:44 +0000 discourse.cakephp.org-post-31588
Friendsofcake/search plugin 6.2 - hide URL search parameters Users search based on what they see, but the corresponding data in the record is confidential. For example, they can select people’s names, but in the record, those same people are identified by their tax code.

]]>
https://discourse.cakephp.org/t/friendsofcake-search-plugin-6-2-hide-url-search-parameters/12811#post_3 Mon, 09 Mar 2026 14:50:42 +0000 discourse.cakephp.org-post-31587
Friendsofcake/search plugin 6.2 - hide URL search parameters I guess my question would be why? The person that searched will surely know what they just searched for, so why hide it? I believe the plugin uses the PRG paradigm, which is generally agreed to be more user-friendly than just posting data.

]]>
https://discourse.cakephp.org/t/friendsofcake-search-plugin-6-2-hide-url-search-parameters/12811#post_2 Mon, 09 Mar 2026 14:24:18 +0000 discourse.cakephp.org-post-31586
Friendsofcake/search plugin 6.2 - hide URL search parameters Hi, I’m looking for a way to hide the search parameters displayed in the browser URL using the plugin in question with CakePHP 4. If that’s not possible, alternative tactics are also welcome. Thanks.

]]>
https://discourse.cakephp.org/t/friendsofcake-search-plugin-6-2-hide-url-search-parameters/12811#post_1 Mon, 09 Mar 2026 08:07:19 +0000 discourse.cakephp.org-post-31585
CakePHP + Azure SQL / System Managed Identity Connections Not an expert in this, but I simply extended the namespace Sqlserver and override the connect() method, and I call it APP/Database/Driver/CustomSqlserver.php

<?php
declare(strict_types=1);

namespace App\Database\Driver;

use Cake\Database\Driver\Sqlserver;
use PDO;

class CustomSqlserver extends Sqlserver
{
    /**
     * Override the connect() method
     * The main reason to override the connect() method is to add the authentication parameter,
     * this is backward compatitable with existing code
     *
     * @return void
     */
    public function connect(): void
    {
        if ($this->pdo !== null) {
            return;
        }
        $config = $this->_config;

        if (isset($config['persistent']) && $config['persistent']) {
            throw new InvalidArgumentException(
                'Config setting "persistent" cannot be set to true, '
                . 'as the Sqlserver PDO driver does not support PDO::ATTR_PERSISTENT',
            );
        }

        $config['flags'] += [
            PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION,
        ];

        if (!empty($config['encoding'])) {
            $config['flags'][PDO::SQLSRV_ATTR_ENCODING] = $config['encoding'];
        }
        $port = '';
        if ($config['port']) {
            $port = ',' . $config['port'];
        }

        $fqdn = '';
        if (count(explode('.', $config['host'])) == 1) {
            $fqdn = $config['host'] . '.database.windows.net';
        } else {
            $fqdn = $config['host'];
        }

        $dsn = "sqlsrv:Server={$fqdn}{$port};Database={$config['database']};MultipleActiveResultSets=false";
        if ($config['app'] !== null) {
            $dsn .= ";APP={$config['app']}";
        }
        if ($config['connectionPooling'] !== null) {
            $dsn .= ";ConnectionPooling={$config['connectionPooling']}";
        }
        if ($config['failoverPartner'] !== null) {
            $dsn .= ";Failover_Partner={$config['failoverPartner']}";
        }
        if ($config['loginTimeout'] !== null) {
            $dsn .= ";LoginTimeout={$config['loginTimeout']}";
        }
        if ($config['multiSubnetFailover'] !== null) {
            $dsn .= ";MultiSubnetFailover={$config['multiSubnetFailover']}";
        }
        if ($config['encrypt'] !== null) {
            $dsn .= ";Encrypt={$config['encrypt']}";
        }
        if ($config['trustServerCertificate'] !== null) {
            $dsn .= ";TrustServerCertificate={$config['trustServerCertificate']}";
        }

        // Custom add this Authentication method
        if ($config['authentication'] !== null) {
            $dsn .= ";Authentication={$config['authentication']}";
        }

        $this->pdo = $this->createPdo($dsn, $config);
        if (!empty($config['init'])) {
            foreach ((array)$config['init'] as $command) {
                $this->pdo->exec($command);
            }
        }
        if (!empty($config['settings']) && is_array($config['settings'])) {
            foreach ($config['settings'] as $key => $value) {
                $this->pdo->exec("SET {$key} {$value}");
            }
        }
        if (!empty($config['attributes']) && is_array($config['attributes'])) {
            foreach ($config['attributes'] as $key => $value) {
                $this->pdo->setAttribute($key, $value);
            }
        }
    }
}

In app.php

use App\Database\Driver\CustomSqlserver;

    'Datasources' => [
        'default' => [
            'className' => Connection::class,
            'driver' => CustomSqlserver::class,
            'authentication' => env('DB_AUTHENTICATION', null),

And finally, set DB_AUTHENTICATION in my local environment for testing with a Service Principle, along with other stuff such as hostname

export DB_HOST='<server_name>'
export DB_NAME='<database_name>'
export DB_AUTHENTICATION='ActiveDirectoryServicePrincipal'

In Azure > App Settings > Configuration, you set DB_AUTHENTICATION to ActiveDirectoryMsi

]]>
https://discourse.cakephp.org/t/cakephp-azure-sql-system-managed-identity-connections/12269#post_3 Sat, 07 Mar 2026 07:02:59 +0000 discourse.cakephp.org-post-31584
CakePHP v4 support/end of life See Semantic Versioning | CakePHP

]]>
https://discourse.cakephp.org/t/cakephp-v4-support-end-of-life/12809#post_5 Sun, 01 Mar 2026 16:48:25 +0000 discourse.cakephp.org-post-31582
Issue TableSchema @dereuromark
I tested more and all versions of php 8 (8.2, 8.3, 8.4, 8.5) have the same behavior on x86/32-bit.

]]>
https://discourse.cakephp.org/t/issue-tableschema/12808#post_10 Fri, 27 Feb 2026 08:14:36 +0000 discourse.cakephp.org-post-31581
CakePHP v4 support/end of life Thanks for the quick reply.

]]>
https://discourse.cakephp.org/t/cakephp-v4-support-end-of-life/12809#post_4 Thu, 26 Feb 2026 14:08:11 +0000 discourse.cakephp.org-post-31580
CakePHP v4 support/end of life We will add a separate page to book.cakephp.org where it’s easier to find this kind of information.

]]>
https://discourse.cakephp.org/t/cakephp-v4-support-end-of-life/12809#post_3 Thu, 26 Feb 2026 12:18:03 +0000 discourse.cakephp.org-post-31579
CakePHP v4 support/end of life As per Home · cakephp/cakephp Wiki · GitHub

4.x End of Life

  • Release bug fixes until September 10 2025 (24 months after 5.0.0).

  • Release security fixes until December 10 2026 (36 months after 5.0.0).

]]>
https://discourse.cakephp.org/t/cakephp-v4-support-end-of-life/12809#post_2 Thu, 26 Feb 2026 12:16:23 +0000 discourse.cakephp.org-post-31578
CakePHP v4 support/end of life Hi,

I can’t find anything on the website - so asking here…

How long will CakePHP v4.x be supported for? Just wanting some ideas of when I should be looking into moving to CakePHP v5.

cheers, Dean

]]>
https://discourse.cakephp.org/t/cakephp-v4-support-end-of-life/12809#post_1 Thu, 26 Feb 2026 09:53:11 +0000 discourse.cakephp.org-post-31577
Issue TableSchema I added the details into the PR, on why is this happening. Quite weird behavior of PHP here indeed.

]]>
https://discourse.cakephp.org/t/issue-tableschema/12808#post_9 Sun, 22 Feb 2026 17:30:09 +0000 discourse.cakephp.org-post-31576
Issue TableSchema so its a x86/32-bit PHP specific problem… weird

]]>
https://discourse.cakephp.org/t/issue-tableschema/12808#post_8 Sun, 22 Feb 2026 14:05:28 +0000 discourse.cakephp.org-post-31575
Issue TableSchema That’s exactly how it is!

]]>
https://discourse.cakephp.org/t/issue-tableschema/12808#post_7 Sun, 22 Feb 2026 14:03:48 +0000 discourse.cakephp.org-post-31574
Issue TableSchema so you are saying you just created a fresh cakephp 5 project, started it and it threw this error when you opened the browser?

]]>
https://discourse.cakephp.org/t/issue-tableschema/12808#post_6 Sun, 22 Feb 2026 11:43:09 +0000 discourse.cakephp.org-post-31573
Issue TableSchema I used default settings, the message appear to create sqlite database for debugkit.

The most interesting thing is that on php 8.4(x64) it works and on php8.4(x86) it doesn’t work.

]]>
https://discourse.cakephp.org/t/issue-tableschema/12808#post_5 Sun, 22 Feb 2026 10:55:43 +0000 discourse.cakephp.org-post-31572
Issue TableSchema I am just wondering where a float length definition would make sense.

]]>
https://discourse.cakephp.org/t/issue-tableschema/12808#post_4 Sun, 22 Feb 2026 00:28:56 +0000 discourse.cakephp.org-post-31571
Issue TableSchema Likely a strict type issue

In TableSchema.php around line 381, there’s likely code like:
new Column($name, $type, $nullable, $default, $length, …)

Where $length comes from database metadata and isn’t being cast to int.

Check out Cast float column attributes to int for PHP 8.4 compatibility by dereuromark · Pull Request #19295 · cakephp/cakephp · GitHub

]]>
https://discourse.cakephp.org/t/issue-tableschema/12808#post_3 Sun, 22 Feb 2026 00:10:40 +0000 discourse.cakephp.org-post-31570
Issue TableSchema How can we reproduce this? What database schema/structure do you have? Can you provide a SQL dump without data?

]]>
https://discourse.cakephp.org/t/issue-tableschema/12808#post_2 Sat, 21 Feb 2026 21:23:26 +0000 discourse.cakephp.org-post-31569
Issue TableSchema Hi,

I used for this test:
OS: windows
CakePhp: 5.3.1 (with debugkit activated)
Php: 8.4 (x86)
When open default page I have following message:
Cake\Database\Schema\Column::__construct(): Argument #5 ($length) must be of type ?int, float given, called in \vendor\cakephp\cakephp\src\Database\Schema\TableSchema.php on line 381

]]>
https://discourse.cakephp.org/t/issue-tableschema/12808#post_1 Sat, 21 Feb 2026 09:48:50 +0000 discourse.cakephp.org-post-31568
Paginator Error @Klaus first of all - please use the “Preformatted text” Feature in this Forum so your code actually gets pasted in properly. I manually cleaned it up for now.

But your “problem” here is this line at the top:

$appnews = $this->get('appNews');

You don’t need to retrieve data inside your templates. Whenever you set a variable inside the controller like so

$this->set(compact('news'));

you automatically have access to it via `$news`

Also you can look at all your accesible variables via Debug Kit “Variables” Panel or just add a simple

pr($this->viewVars);

in your template (and make sure your Debug Mode is active) to see what your current scope of variables has to offer.

]]>
https://discourse.cakephp.org/t/paginator-error/12806#post_2 Tue, 17 Feb 2026 19:03:05 +0000 discourse.cakephp.org-post-31566
Paginator Error Hello, I am moving to cake 5.1 and receive Paginator Error in the template inthe header tags.
My Controller function:

public function index($id = null) {
    $query = $this->News->find();

    $news = $this->paginate($query, [
        'scope' => 'news'
    ]);
    $this->set(compact('news'));
    $this->render('/Homepage/News/index');
}

Error: TypeError: Cake\View\View::get(): Argument #1 ($var) must be of type string, int given
called in PaginatorHelper.php on line 142
Template

<?php
/**
 * @var \\App\\View\\AppView $this
 * @var iterable<\\App\\Model\\Entity\\Article> $articles
 */
$yesno = $this->get('appYesNo');
$appnews = $this->get('appNews');
?>
<?= $this->Element('navigation', ['navi' => $prodItem]); ?>
<div class="news index content">
    <?= $this->Html->link(__('Neue Neuigkeit'), ['action' => 'add'], ['class' => 'button float-right']) ?>
    <h3><?= __('Neuigkeiten') ?></h3>
    <div class="table-responsive">
        <table>
            <thead>
                <tr>
                    <th width="40"><?= $this->Paginator->sort('id') ?></th>
                    <th width="300"><?= $this->Paginator->sort('title') ?></th>
                    <th><?= $this->Paginator->sort('type') ?></th>
                    <th><?= $this->Paginator->sort('folder') ?></th>
                    <th><?= $this->Paginator->sort('active') ?></th>
                    <th><?= $this->Paginator->sort('login') ?></th>
                    <th width="200" class="actions"><?= __('Actions') ?></th>
                </tr>
            </thead>
            <tbody>
                <?php foreach ($news as $news): ?>
                    <tr>
  <td><?= h($news->title) ?></td>
                    <td>
                        <?php
                        echo $appnews[$news->type];
                        ?>
                    </td>
                    <td><?= h($news->folder) ?></td>
                    <td>
                        <?php
                        echo $yesno[$news->active];
                        ?>
                    </td>
                    <td>
                        <?php
                        echo $yesno[$news->login];
                        ?>
                    </td>
                    <?= $this->Element('viewArticleAction', array('recCon' => 'News', 'action' => 'singleNews', 'recId' => $news->id, 'parentId' => $news->id)); ?>   
                    </tr>
                <?php endforeach; ?>
            </tbody>
        </table>
    </div>
    <div class="paginator">
        <ul class="pagination">
            <?= $this->Paginator->first('<< ' . __('first')) ?>
            <?= $this->Paginator->prev('< ' . __('previous')) ?>
            <?= $this->Paginator->numbers() ?>
            <?= $this->Paginator->next(__('next') . ' >') ?>
            <?= $this->Paginator->last(__('last') . ' >>') ?>
        </ul>
        <p><?= $this->Paginator->counter(__('Page {{page}} of {{pages}}, showing {{current}} record(s) out of {{count}} total')) ?></p>
    </div>
</div>

Whats the problem? Kid regards Klaus

]]>
https://discourse.cakephp.org/t/paginator-error/12806#post_1 Tue, 17 Feb 2026 16:58:32 +0000 discourse.cakephp.org-post-31565
Upgraded from 4 to 5.3.1, missing controller error starting app with netbeans All good, you are not offending anyone here :smiley:

I just wanted to clear things up so you understand, that PHP is not a “compiled” language like Java is.

If you have any problems feel free to just post it in here or go to our slack or discord support channel.

]]>
https://discourse.cakephp.org/t/upgraded-from-4-to-5-3-1-missing-controller-error-starting-app-with-netbeans/12803#post_5 Fri, 13 Feb 2026 17:39:52 +0000 discourse.cakephp.org-post-31563
Upgraded from 4 to 5.3.1, missing controller error starting app with netbeans Thanks for your response.

I did post yesterday to say I’d managed to get it working. I would have marked it as resolved but for some reason I couldn’t edit the original post, only my additional comment where I said I’d fixed it.

Re your comment about Netbeans, I’ve been using it as a debugger for a few years and it works well on a local web application, as one might expect as it comes from “Friends of Apache”.

I’m sorry if my use of the word “start” offends you, I consider the web app has “started” when the home page appears, which I tried to indicate in my original post. I came to web development late in life, I’m afraid I predate the internet. Now at the grand old age of 80 perhaps my vocabulary differs somewhat from yours :slight_smile:

]]>
https://discourse.cakephp.org/t/upgraded-from-4-to-5-3-1-missing-controller-error-starting-app-with-netbeans/12803#post_4 Fri, 13 Feb 2026 16:46:32 +0000 discourse.cakephp.org-post-31561
Upgraded from 4 to 5.3.1, missing controller error starting app with netbeans Netbeans is primarily a Java IDE, so how you “start” a CakePHP project with Netbeans is beyond my knowledge.

I’d recommend you take a look at Installation Guide | CakePHP and learn about how webservers work and what a “docroot” is.

Unless you use bin/cake server (or Netbeans calls that via your project settings), then its the PHP Built In Webserver.

]]>
https://discourse.cakephp.org/t/upgraded-from-4-to-5-3-1-missing-controller-error-starting-app-with-netbeans/12803#post_3 Fri, 13 Feb 2026 10:23:23 +0000 discourse.cakephp.org-post-31560
Upgraded from 4 to 5.3.1, missing controller error starting app with netbeans Fixed it. In the Run Configuration I blanked out “Index File” which in the Version 4 config had “index.php” which was selected from the “webroot” directory.
Now it works.

]]>
https://discourse.cakephp.org/t/upgraded-from-4-to-5-3-1-missing-controller-error-starting-app-with-netbeans/12803#post_2 Thu, 12 Feb 2026 17:57:29 +0000 discourse.cakephp.org-post-31559
Upgraded from 4 to 5.3.1, missing controller error starting app with netbeans I’ve upgraded my test system (wildows 11, xampp) to 5.3.1 from 4.4.17. If I start the app from firefox directly (localhost/) I see the homepage with a couple of “deprecated” messages.
However if I start the app with netbeans (debug project or run project) I get a “Missing controller” error for “index.phpController”.

No changes the the netneans project settings, I can go back to the old 4.4.17 project & it works fine.

I feel I must be missing something but I know not what.

Has anyone seen this or can throw any light on it?

tia

Peter

]]>
https://discourse.cakephp.org/t/upgraded-from-4-to-5-3-1-missing-controller-error-starting-app-with-netbeans/12803#post_1 Wed, 11 Feb 2026 17:49:06 +0000 discourse.cakephp.org-post-31558
findAllByColumn1OrColumn2
efjot:

What I wnat to do is searching different values in different fields, eg email = [email protected] and role_id = 1 and status_id = 2

select * from users where [email protected] or role_id = 1 or status_id = 2

If you REALLY want OR search instead of AND (which is weird, but ok), then you probably need the custom callback here:

  ->add('q', 'Search.Callback', [
      'callback' => function ($query, $args) {
          $value = $args['q'] ?? null;
          if ($value === null) {
              return $query;
          }

          return $query->where([
              'OR' => [
                  'column1' => $value,
                  'column2' => $value,
              ],
          ]);
      },
  ]);

for the same fields.

In your case, with 3 different values, probably more like

      ->add('q', 'Search.Callback', [
          'callback' => function ($query, $args) {
              $or = [];

              if (!empty($args['col1'])) {
                  $or[] = ['column1' => $args['col1']];
              }
              if (!empty($args['col2'])) {
                  $or[] = ['column2' => $args['col2']];
              }
              if (!empty($args['col3'])) {
                  $or[] = ['column3' => $args['col3']];
              }

              return $or ? $query->where(['OR' => $or]) : $query;
          },
      ]);

This yields column1 = val1 OR column2 = val2 OR column3 = val3, each with its own value.

But usually searches are AND combined, so normal value() and like() filters should be totally sufficient.

]]>
https://discourse.cakephp.org/t/findallbycolumn1orcolumn2/12799#post_7 Thu, 05 Feb 2026 21:46:10 +0000 discourse.cakephp.org-post-31555
findAllByColumn1OrColumn2 Use what I told you: A proper filter collection class. Using this adhoc add() on the manager itself is not a good idea.

With the class itself you are more flexible in general, and reusable for other actions if needed.

As for your concrete issue:
Why are you not using value() on role? after all, you are doing the same here as for user_id/status_id etc (direct value match).

]]>
https://discourse.cakephp.org/t/findallbycolumn1orcolumn2/12799#post_6 Thu, 05 Feb 2026 21:44:12 +0000 discourse.cakephp.org-post-31554
findAllByColumn1OrColumn2 I do not get it running.

in my searchManager() function in my UserTable I put in there

$this->getBehavior('Search')->searchManager()
        ->value('user_id')
        ->add('email', 'Search.Like', [
            'before' => true,
            'after' => true,
            'fieldMode' => 'OR',
            'comparison' => 'LIKE',
            'wildcardAny' => '*',
            'wildcardOne' => '?',
            'fields' => ['email'],
        ])

This will find user by email. But when I add there a second field like role_id

$this->getBehavior('Search')->searchManager()
        ->value('user_id')
        ->add('email', 'Search.Like', [
            'before' => true,
            'after' => true,
            'fieldMode' => 'OR',
            'comparison' => 'LIKE',
            'wildcardAny' => '*',
            'wildcardOne' => '?',
            'fields' => ['email', 'role_id'],
        ])

Then I get an error because this tries to search the email also in the field role_id, which is a number.

and when I add another field

$this->getBehavior('Search')->searchManager()
        ->value('user_id')
        ->add('email', 'Search.Like', [
            'before' => true,
            'after' => true,
            'fieldMode' => 'OR',
            'comparison' => 'LIKE',
            'wildcardAny' => '*',
            'wildcardOne' => '?',
            'fields' => ['email'],
        ])
        ->add('role_id', 'Search.Like', [
            'before' => false,
            'after' => false,
            'fieldMode' => 'AND',
            'comparison' => 'LIKE',
            'wildcardAny' => '*',
            'wildcardOne' => '?',
            'fields' => ['role'],
        ]);

The role_id will be ignored on the search query.

What I found in docu was that I can use the add() methode several times. But it does not work in my example.

In additional, I do not know, what else can I use instead of like search. I want to find where role_id = 2

Sorry but when I read docu, I have a lot of questions

]]>
https://discourse.cakephp.org/t/findallbycolumn1orcolumn2/12799#post_5 Thu, 05 Feb 2026 20:30:34 +0000 discourse.cakephp.org-post-31553
How to make sure entities are in a valid state?
KevinPfeifer:

Well then its up to what you define as domain objects :grin:

I’m trying to go with the standard definition here, which is the model that describes a key aspect of my business domain.

One way would be to create a seperate model in ie. /domain, and then using the data from the entity to run the actual business logic on it. That way, the CakePHP models are not abused for domain matters and the domain stays free of framework logic.

]]>
https://discourse.cakephp.org/t/how-to-make-sure-entities-are-in-a-valid-state/12801#post_6 Thu, 05 Feb 2026 12:01:32 +0000 discourse.cakephp.org-post-31552
How to make sure entities are in a valid state? That said: If you really want it validated upon creating/patching, then use normal validation rules. Afterwards, getErrors() will give you the issues if any.

]]>
https://discourse.cakephp.org/t/how-to-make-sure-entities-are-in-a-valid-state/12801#post_5 Wed, 04 Feb 2026 18:33:57 +0000 discourse.cakephp.org-post-31551
How to make sure entities are in a valid state? Well then its up to what you define as domain objects :grin:

]]>
https://discourse.cakephp.org/t/how-to-make-sure-entities-are-in-a-valid-state/12801#post_4 Wed, 04 Feb 2026 15:09:52 +0000 discourse.cakephp.org-post-31550
How to make sure entities are in a valid state? Thanks for the link, I wasn’t aware of that part of the docs. Shouldn’t business rules / invariants be framework agnostic? There’s a lot of CakePHP specific code in those rule checks.

Interesting. I thought it was the other way round, table classes being just “dumb” persistence models (hence the Table suffix).

Btw. the doc also states:

entities represent individual rows or domain objects in your application

]]>
https://discourse.cakephp.org/t/how-to-make-sure-entities-are-in-a-valid-state/12801#post_3 Wed, 04 Feb 2026 14:24:41 +0000 discourse.cakephp.org-post-31549
How to make sure entities are in a valid state?
Schroeder:

An Invoice with 0 line items makes little sense. How can I catch this?

What you are looking for is Application Rules

Those are applied when you try to save an entity (and maybe associated entities as well)

As the docs say

rules focus on comparing data against the existing state of your application and/or network.

So your entity state can/must be wrong as it needs to hold the wrong state, but the check logic is being done by the table instance.

If application rules don’t pass the saving process fails.


What you expect is, that validation happens the moment an entity gets state injected into it, which is not what Cake is built upon.

Entities are dumb objects which just repesent state (or desired state) in a row/in the db

Table objects do the logic and validation.

]]>
https://discourse.cakephp.org/t/how-to-make-sure-entities-are-in-a-valid-state/12801#post_2 Wed, 04 Feb 2026 14:09:52 +0000 discourse.cakephp.org-post-31548
How to make sure entities are in a valid state? Hi,

I use CakePHP’s entities as domain models mostly, where I keep the business rules. For those rules to apply correctly, it is important that the object is in a valid state, ie. `status` must be a `InvoiceStatus` enum. The way it is, I must pass an array of values when I instantiate the object:

new Invoice([ 'status' => 'notWhatIexpected' ]);

Invoice is created with an invalid property.

Same applies to `LineItem`, which belongs to `Invoice`. An Invoice with 0 line items makes little sense. How can I catch this? I was thinking about a static creation method, but what is the CakePHP way?

Copilot’s suggestion is to check all values manually before instantiating the invoice, but this doesn’t seem right. Because the validity of the Invoice model is a kind of business rule in itself (“An invoice status can be draft or final”). Therefore I want to encapsulate this logic in the Invoice model.

Regards

]]>
https://discourse.cakephp.org/t/how-to-make-sure-entities-are-in-a-valid-state/12801#post_1 Wed, 04 Feb 2026 13:14:54 +0000 discourse.cakephp.org-post-31547
findAllByColumn1OrColumn2 everything is possible, see docs.
you can always make a custom callback if none of the default ones work.
but it is designed to work with unlimited number of fields and combinations.

]]>
https://discourse.cakephp.org/t/findallbycolumn1orcolumn2/12799#post_4 Tue, 03 Feb 2026 03:46:50 +0000 discourse.cakephp.org-post-31545
findAllByColumn1OrColumn2 Hi dereuromark,

I downloaded the search plugin and I tried to get it running, reading docu.

But for now it looks like, I can search 1 search element in different fields of a table.

What I wnat to do is searching different values in different fields, eg email = [email protected] and role_id = 1 and status_id = 2

select * from users where [email protected] or role_id = 1 or status_id = 2

But I am not sure how to configure the search plugin

]]>
https://discourse.cakephp.org/t/findallbycolumn1orcolumn2/12799#post_3 Mon, 02 Feb 2026 21:17:40 +0000 discourse.cakephp.org-post-31544
findAllByColumn1OrColumn2 The cleanest approach is using FilterCollection classes and GitHub - FriendsOfCake/search: CakePHP: Easy model searching
This way it is future proof, easy to review/adjust and user-friendly (clean PRG via query strings).

See e.g.

for a live demo implementation.

]]>
https://discourse.cakephp.org/t/findallbycolumn1orcolumn2/12799#post_2 Mon, 02 Feb 2026 04:28:50 +0000 discourse.cakephp.org-post-31543
findAllByColumn1OrColumn2 Hi together, I try to implement a search bar for alist of entrys.

I list all users from database but now I want to filter either by email, or by role or by status.

I tried to use the following option for retrieving Data: Dynamic Finders

But when I try to use

$this->Users->findAllByEmailOrRoleOrStatus($email, $role, $status);

and one of the fields is not set, the I get an error.

Expression `Users.email` has invalid `null`

How can I use this dynamically? Some ideas?

Cheers Frank

]]>
https://discourse.cakephp.org/t/findallbycolumn1orcolumn2/12799#post_1 Sun, 01 Feb 2026 21:40:37 +0000 discourse.cakephp.org-post-31542
Deny access on all pages, but not login Hah….

All I have to say is, thanks for your effort creating this video. It helped me a lot.

cheers Frank

]]>
https://discourse.cakephp.org/t/deny-access-on-all-pages-but-not-login/12798#post_5 Sun, 01 Feb 2026 21:04:33 +0000 discourse.cakephp.org-post-31541
Deny access on all pages, but not login After the Authentication Plugin has been setup (Middleware added and Component loaded) it will by default require all actions to be logged in as that is the best practice.

What you need to do is add your “not logged in actions” to be called without a user.

Look at CMS Tutorial - Authentication | CakePHP and search for addUnauthenticatedActions

You can also check out my auth workshop from 3 years ago (but still valid!)

WORKSHOP - Authentication & Authorization by Kevin Pfeifer

]]>
https://discourse.cakephp.org/t/deny-access-on-all-pages-but-not-login/12798#post_4 Fri, 30 Jan 2026 07:37:16 +0000 discourse.cakephp.org-post-31540
REST API, pagination results Thank you very much, it didn’t offer this method to me, because I had this in the annotation in the controller:

* @method \App\Model\Entity\User[]|\Cake\Datasource\ResultSetInterface paginate($object = null, array $settings = [])

correct

* @method \App\Model\Entity\User[]|\Cake\Datasource\Paging\PaginatedResultSet paginate($object = null, array $settings = [])
]]>
https://discourse.cakephp.org/t/rest-api-pagination-results/12797#post_3 Thu, 29 Jan 2026 17:47:52 +0000 discourse.cakephp.org-post-31539