cakephp-3.0

What “type” do I specify in addCase to return a column?

末鹿安然 提交于 2019-12-02 04:06:46
I'm trying to get a query working using a case statement, and can't figure out how to get the case to return a column value instead of a constant. I have the query working perfectly, except that the column names I'm providing for the results are being quoted or otherwise mishandled by Cake or maybe PDO somewhere down in a layer that I can't dig my way through. I got as far down as bindValue, but none of the documentation I encountered along the way tells me how to do this. I have found this example comment: $statement->bindValue(1, 'a title'); $statement->bindValue(2, 5, PDO::INT); $statement-

How to query translated content when using the translate behavior?

て烟熏妆下的殇ゞ 提交于 2019-12-02 03:08:17
问题 My website is in multiple languages so an article's title depends on the local. But there's a problem: How can I search for an article in another language? Right now, the only way is by typing the title in english so that cakePHP retrieves the name in french, for exmple. I can't search for it in french. For exemple: When I search for "Hello" I find the article named "Bonjour" But when I search for "Bonjour" I can't find any article. So how do I search in another language? It seem that Cakephp

CakePHP 3 - Where is custom datasource?

一笑奈何 提交于 2019-12-02 03:07:05
I have a large number of CakePHP 2 web applications, many of them use remote data over the custom DataSource. I'm reading the documentation of CakePHP 3, but I can not find instructions for creating custom datesource. My next project also requires a custom DataSource (ArangoDB), so I planned to build it with the new version of CakePHP. Please do specify where and how to build a DataSource in CakePHP 3. Thank You. Just look at the code of any existing database driver and see how it is built? There is nothing in the book yet about how to create your own datasource. ArangoDB seems to be yet

cakephp 3.0 using tableprefix?

时光毁灭记忆、已成空白 提交于 2019-12-02 03:06:41
问题 Moving on from a cakephp 2 application, I am stuck on trying to use $tablePrefix in my models. Is this still available in Cake 3? Or how can I use something else (please explain). 回答1: Table prefixes are gone for now. There is an open PR, however it's not clear at this point when, and if at all this is going to make it: https://github.com/cakephp/cakephp/pull/4505 As mentioned by Lorenzo in the comments, an alternative might be using events to initialize models with a prefixed table name: For

How to use multiple Auth components?

和自甴很熟 提交于 2019-12-02 02:41:12
I configure a Auth component to "Admin page", using the users model. But now, I also want create/configure a Auth to the clients. I try "rewrite" the inialize() //This is in my ClientsController.php public function initialize() { $this->loadComponent('RequestHandler'); $this->loadComponent('Flash'); $this->loadComponent('Auth', [ 'authenticate' => [ 'Form' => [ 'userModel' => 'clients', 'fields' => ['username' => 'client_email', 'password' => 'client_password'] ] ], 'loginRedirect' => [ 'controller' => 'Clients', 'action' => 'index' ], 'logoutRedirect' => [ 'controller' => 'Clients', 'action'

cakephp 3.0 using tableprefix?

余生颓废 提交于 2019-12-02 02:29:28
Moving on from a cakephp 2 application, I am stuck on trying to use $tablePrefix in my models. Is this still available in Cake 3? Or how can I use something else (please explain). Table prefixes are gone for now. There is an open PR, however it's not clear at this point when, and if at all this is going to make it: https://github.com/cakephp/cakephp/pull/4505 As mentioned by Lorenzo in the comments, an alternative might be using events to initialize models with a prefixed table name: For people still wanting support for prefixes in their tables, there is a way to support it using events. This

cakephp Model validation error message not displaying in hasOne association

╄→гoц情女王★ 提交于 2019-12-02 02:21:40
i want to do model validation with association in a single form. i have two tables users (parent table) and user_details (child table).now model validation is working for users table only.i want it for userDetails table also. relation between them is hasOne . validation working for only users table because i have created newEntity for users table only. usersController.php (controller code) public function add() { $user = $this->Users->newEntity(); $userDetail = $this->UserDetails->newEntity(); if ($this->request->is('post')) { $user = $this->Users->patchEntity($user, $this->request->getData())

How to query translated content when using the translate behavior?

爷,独闯天下 提交于 2019-12-02 01:27:50
My website is in multiple languages so an article's title depends on the local. But there's a problem: How can I search for an article in another language? Right now, the only way is by typing the title in english so that cakePHP retrieves the name in french, for exmple. I can't search for it in french. For exemple: When I search for "Hello" I find the article named "Bonjour" But when I search for "Bonjour" I can't find any article. So how do I search in another language? It seem that Cakephp search first in default language to then get the traductions. In my controller: $this->Ingredients-

How to update or save a specific field only in CakePHP 3.0?

我是研究僧i 提交于 2019-12-02 01:00:18
问题 I want to update or save a specific field of a table in Cakephp 3.0. I tried Updating Data from the Cakebook and it is saving the data but problem is that it is also saving the modified field assigned as datetime in database. I do not want to save this field in that case. How do i do that? Thanks in advance 回答1: When you don't want callbacks to be triggered, just use updateAll() $table->updateAll(['field' => $newValue], ['id' => $entityId]); 来源: https://stackoverflow.com/questions/30305408

How to create CSRF token for Cakephp 3 PHPunit testing?

给你一囗甜甜゛ 提交于 2019-12-01 22:53:30
I am trying to get my unit tests working again after enabling CSRF tokens and SSL in my CakePHP 3 app. How do I create or generate a token for a test like the following? Or do I just disable it for testing purposes? public function testLogin() { $this->get('/login'); $this->assertResponseOk(); $data = [ 'email' => 'info@example.com', 'password' => 'secret' ]; $this->post('/login', $data); $this->assertResponseSuccess(); $this->assertRedirect(['controller' => 'Users', 'action' => 'dashboard']); } Genar The official documentation has good approach since version 3.1.2 . You only have to call