Questions tagged [cakephp-3.x]

Questions about 3.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.

963 questions
14
votes
2 answers

Order 'Contain' Model in CakePHP 3.x

I have multiple Things in AnotherThing now I am trying to order them in my edit action in my AnotherThing Controller - I can access the Things just fine in my edit, but I want to sort them differently (not over their ID), for example…
Isengo
  • 2,004
  • 3
  • 21
  • 43
10
votes
1 answer

How to Create a URL in Controller like HtmlHelper

TLDR: How can I create a URL in the Controller similar to how I can use the HtmlHelper to create URLs in a View? Problem: I want to print the url of a controller action, in my controller (because I create my JSON string in my controller, not in a…
mrdaliri
  • 7,148
  • 22
  • 73
  • 107
9
votes
3 answers

How to get last run query in CakePHP 3.2?

I want to get the last executed query in CakePHP 3.2, I have used the following in CakePHP 2.x before:- function getLastQuery() { Configure::write('debug', 2); $dbo = $this->getDatasource(); $logs = $dbo->getLog(); …
sradha
  • 2,216
  • 1
  • 28
  • 48
8
votes
4 answers

"Cannot convert value to string" when retrieving data (belongsToMany relationship)

I'm using CakePHP 3.3.6 and MySQL 5.7.13. I have these three tables in my database (amongst others) : collections, tags and the join table collections_tags. collections Table CREATE TABLE IF NOT EXISTS `database`.`collections` ( `id` INT UNSIGNED…
7
votes
2 answers

CakePHP 3 debug session timeout

We moved our application to a new server and now the session is expiring too soon (not sure about exact hours) for the logged in users. We tried many things to find out why the session is expiring in a production environment but until now we are…
xinaris
  • 454
  • 1
  • 4
  • 16
7
votes
1 answer

Check if record exists in CakePHP3.5

The Following Code returns only a error :Record not found in table "users" if($this->Users->get($uid)->isEmpty()) { //do something } Because the Table is empty, i want to customize this if the table is empty, and call a new page…
Der Admin81
  • 425
  • 3
  • 9
  • 19
7
votes
3 answers

How to define CSRF token in ajax call in Cakephp 3. Also How CSRF can be off for some ajax requests

In Cakephp3 when the Csrf component is enabled. How I can use it in ajax call. In this beforeSend parameter of ajax csrf token is set in header. What is the value of csrfToken. As it gives error csrfToken is not defined beforeSend: function(xhr){ …
ParminderBrar
  • 145
  • 1
  • 3
  • 13
7
votes
2 answers

How to output custom HTTP body contents with CakePHP 3.4? Echoing causes "Unable to emit headers" error

Using CakePHP 3.4, PHP 7.0. I'm attempting to do a really simple controller method to output some JSON. It is outputting "Cannot modify headers...". public function test() { $this->autoRender = false; echo json_encode(['method' =>…
ryantxr
  • 4,119
  • 1
  • 11
  • 25
7
votes
1 answer

Confusing Validation vs. Application Rules in CakePHP3

Multiple questions about validation which may belong together, because they are all kind of adressing the new validation concept in CakePHP 3. I have read the chapters (1, 2, 3) in the cookbook multiple times but honestly I don't understand how to…
Oops D'oh
  • 941
  • 1
  • 15
  • 34
6
votes
3 answers

Print SQL query of ORM query builder in cakephp3

How to print ORM query $query = $articles->find('all')->contain(['Comments']); For example print => SELECT * FROM comments WHERE article_id IN (comments);
Fury
  • 4,643
  • 5
  • 50
  • 80
5
votes
1 answer

CakePHP 3 + ORM Query builder and column name escape

A've already rewrite some application from CakePHP 2 to CakePHP 3. I have some structure in database with column: key (autogenerated key-string). In mysql key is a keyword, so when I write an SQL Query I have to escape it as INSERT INTO table…
plugowski
  • 313
  • 1
  • 3
  • 8
5
votes
1 answer

cakephp 3.x Saving Nested (deep) Association

I have product data coming from a 3rd party service call that I then create an object from and save to my MySQL DB. My models are as follows: 'products' hasMany>> 'product_skus' hasMany>> 'product_sku_attributes' table relationships In my…
stoff
  • 53
  • 3
5
votes
3 answers

How to bake admin (prefixed) code with CakePHP 3?

Can anyone tell me what is the official way to create CRUD for admin back-end? In CakePHP 2 the baked code was extended with 'admin_' before the function names and for the view files. In CakePHP it seems I can't find any direct information on how…
Lucky
  • 95
  • 1
  • 7
5
votes
3 answers

Same table model association twice in cakephp 3.2

I have done model association in cake 3.2 Here i have done it for one id of same table . I have tried to do it for other one ,but its not working at all below is the flow. This output i am getting { "id": 1, "publisher_id": 133, "user_id":…
sradha
  • 2,216
  • 1
  • 28
  • 48
5
votes
1 answer

CakePHP deleteAll for many to many relationship does not remove join records

I'm on CakePHP v3.17 w/ Postgres 9.4 I'm trying to get $this->SomeTable->deleteAll([...]) to remove the records in the join table too. Imaging a bus system with a table for Stops and a table for Routes. Stops are associated with many routes (because…
emersonthis
  • 32,822
  • 59
  • 210
  • 375
1
2 3
64 65