Skip to content

Tag: cakephp

CakePHP3: How to run custom SQL query in table model

In CakePHP 3, is it possible to run a custom SQL query from within a table model? If so, how? I tried the following from within a table model: (The query is deliberately simple for example purposes.) But then, when I loop through the $rows, this results in an infinite loop. I’m surprised CakePHP 3 does …

Clone entity and all related entities in CakePHP 3

In my CakePHP 3 app, I have a somewhat elaborate tree of entities that I need to clone and save. The root of the structure is a Questionnaire, a Questionnaire hasMany Questions, each Question hasMany Fields, etc. (it goes deeper). Now I want the user to be able to define a new questionnaire by copying an old …

Virtual fields with Cakephp 3

I need to have a virtual property in my user entity. I followed the CakePHP book. UserEntity.php In a controller I followed exactly the book and I only get a null value. Answer According to @ndm, the problem was due to a bad file naming. I named the user entity class UserEntity.php. The CakePHP name conventio…

Cakephp Auth->user() null

In my CakePHP app, I want to include a login form on every page with a login button if the user is not logged in and a logout button if they are logged in. Here is my Auth configuration in AppController.php I want to set a flag that is usable in all the views to check if the user is