cakephp-3.0

Why does formatting a date return the wrong year?

你说的曾经没有我的故事 提交于 2019-12-18 09:12:29
问题 I want to print formatted dates on my page. I have an object date and I use $this->Time->format() for formatting. Everything works fine before December 27th. Unfortunately all dates after the December 26th, formatting change my year number. This is my debug($date) object(Cake\I18n\Time) { 'time' => '2015-12-30T00:00:00+0000', 'timezone' => 'UTC', 'fixedNowTime' => false } This is my debug($this->Time->format($date, 'YYYY')) '2016' I tried to use i18nFormat but I have the same problem. Here is

Cakephp3 : using another model in a controller

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-18 07:26:29
问题 I started an app with CakePHP3 and i need to record some users's actions. So, I have migrated my log structure, I have baked my controller & model and now, I try to get a log when a user log in. I updated my UsersController like this: namespace App\Controller; use App\Controller\AppController; use App\Model\Table\LogsTable; use App\Model\Entity\User; use App\Model\Entity\Log; class UsersController extends AppController { public function login(){ $this->viewBuilder()->layout('external'); $user

Cakephp3 : using another model in a controller

萝らか妹 提交于 2019-12-18 07:26:06
问题 I started an app with CakePHP3 and i need to record some users's actions. So, I have migrated my log structure, I have baked my controller & model and now, I try to get a log when a user log in. I updated my UsersController like this: namespace App\Controller; use App\Controller\AppController; use App\Model\Table\LogsTable; use App\Model\Entity\User; use App\Model\Entity\Log; class UsersController extends AppController { public function login(){ $this->viewBuilder()->layout('external'); $user

CakePHP 3.0 vendor class not found

眉间皱痕 提交于 2019-12-18 07:11:13
问题 I'm adding an external class to a cake 3.0 app by putting it to /vendor/name folder and requiring it from a component like this: require_once( $_SERVER['DOCUMENT_ROOT'].'/project/vendor/external/testClass.php'); But when I try to getInstance(); of a class - I get an error Class 'App\Controller\Component\Test_Class' not found I am calling this from a component (thus the \Controller\Component). What is it that i'm doing wrong? 回答1: CakePHP 3.0 uses namespaces. So use proper namespace for your

CSRF token mismatch in post request in 3.6 version

自作多情 提交于 2019-12-18 06:51:32
问题 I have two different apps of cakephp. One has a version 3.5 and other 3.6. When i used and built 3.5 app i did not have a problem of CSRF matching in post request. But now as i am using 3.6 it is giving me error of CSRF token. Although in both app's AppController , CSRF component is disable. //$this->loadComponent('Csrf'); i am using simple post request like this: $.ajax({ type: "POST", url: "../user/my_action", dataType: 'json', success: function (data) { set_data(data.response); } }); What

CakePHP 3 Raw SQL Query

≯℡__Kan透↙ 提交于 2019-12-18 04:40:14
问题 I'm using CakePHP 3, I need to run a raw SQL query on multiple tables. In CakePHP 2, this could be done by using the query() method on any model ( $this->Messages->query("select..") ). I need the method that allows me to run a SQL query in CakePHP 3. Following is the code snippet I'm using: $aumTable = TableRegistry::get('Messages'); $sql = "SELECT (SELECT COUNT(*) FROM `messages`) AS `Total_Count`, (SELECT COUNT(*) FROM `messages_output`) AS `Total_Output_Count`, (SELECT COUNT(*) FROM

Check if record exists in CakePHP3

流过昼夜 提交于 2019-12-17 23:24:45
问题 In CakePHP 2 I always used empty to check if there any result. <?php $result = $this->Modelname->find('first', ['conditions' => ['field' => 'value'] ] ); if ( empty($result) ) { // Bad Request } In CakePHP 3 it looks weird to me. $fancyTable = TableRegistry::get('FancyTable'); $query = $fancyTable->find()->where(['name' => 'fancy', 'active' => 0]); if ( 0 === $query->count() ) { // Bad Request } Is this the right way? 回答1: You can do: $fancyTable = TableRegistry::get('FancyTable'); $exists =

How do I create a keyValue pair (display field) by combining/having two fields in CakePHP 3?

一个人想着一个人 提交于 2019-12-17 10:59:38
问题 I need help getting two values (for human friendly dropdown) in a key-value pair using find or get or anything else. I need help with the simplest method of doing this in CakePHP. Here's my attempt: in my controller $users = $this->LocationsUser->Users->find('list', [ 'limit' => 1, 'keyField' => 'id', 'valueField' => ['first_name', 'last_name'] ])->where(['id' => $id]); In my view echo $this->Form->input('user_id', [ 'options' => $users, 'type' => 'select', 'multiple' => false, ]); The result

How to use requestAction in cakephp 3.0

人走茶凉 提交于 2019-12-14 04:08:54
问题 At 2.0, I use requestAction like this: <?=$this->Form->input('list',array('options'=>$this->requestAction(……)?> But At 3.0, I use requestAction nothing display. I don't know how to write options data source. 回答1: In Cake 3, the results from requestAction must be returned through the response object rather than directly like they were in Cake 2. This is most easily accomplished with JSON encoding. In the function that you are calling through requestAction: $options = $table->find(...); $this-

CakePHP 3 on Bluehost Console Commands Do Not Function

早过忘川 提交于 2019-12-14 03:57:38
问题 I'm attempting to get a CakePHP 3 app setup on a shared hosting solution provided by Bluehost. When I attempt to bin/cake bake from a console (or any cake commands, really) I get the following output: ################################################################################ # # Bake is a shell script for running CakePHP bake script # # CakePHP(tm) : Rapid Development Framework (http://cakephp.org) # Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org) # # Licensed