cakephp-3.0

Cakephp 3.x ADmad/JwtAuth doesn't work

这一生的挚爱 提交于 2019-12-11 10:28:54
问题 Currently I'm working with cakephp 3.1 to develop a restful API for an android app. I've been trying to use the ADmad/JwtAuth.Jwt component but I can't make it work, and I dont know why. I've followed this tutorial without using the CRUD component.This is my code: AppController.php public function initialize() { parent::initialize(); $this->loadComponent('RequestHandler'); $this->loadComponent('Auth', [ 'storage' => 'Memory', 'authenticate' => [ 'Form'=> ['fields' => ['username' => 'email',

Cakephp 3: How to ignore beforefind for specific queries?

大城市里の小女人 提交于 2019-12-11 09:37:02
问题 I am working on multilingual posts. I have added beforefind() in the PostsTable so I can list posts for current language public function beforeFind(Event $event, Query $query) { $query->where(['Posts.locale' => I18n::locale()]); } In order to allow users duplicate posts in different languages i wrote following function: public function duplicate(){ $this->autoRender = false; $post_id= $this->request->data['post_id']; $post = $this->Posts ->findById($post_id) ->select(['website_id', 'category

CakePHP 3 - How to use Trim() before validation NotEmpty?

若如初见. 提交于 2019-12-11 09:28:50
问题 My form validate empty fields, but if the user use "space", the validation handle how one character.. How to use Trim() in Model-Table for it not happen? 回答1: Assuming that you have a title column in Posts table and you want to trim title before validating. put following code in src\Model\Table\PostsTable.php public function beforeMarshal(Event $event, ArrayObject $data) { $data['title'] = trim($data['title']); } and add following two lines at the top of src\Model\Table\PostsTable.php use

CakeDc/users how to work with permissions?

孤人 提交于 2019-12-11 07:07:55
问题 I installed CakeDC/users run migration, created the super user, copied the users.php to config/ directory. And now in my website all pages are redirecting to login page. And i can't change this thing, cause i not well understand how permissions work. My needs are to allow all pages on site, and block access only for one page with personal data for the user loggedin. Any help, suggest readings, examples are welcome, BIG thanks! 回答1: You will need to allow all actions in the beforeFilter of

CakePHP: Loading Model in Controller

蓝咒 提交于 2019-12-11 06:59:47
问题 I would like to load my Model in my Controller. The model is not associcated with a table in the database, thus it is probably not able to follow CakePHP's ORM. I have the following code currently (this is my Model): <?php namespace App\Model\Json; use Cake\Filesystem\File; class Processes { public static function getData() { $file = new File('process_data.json'); $json = $file->read(true, 'r'); $jsonstd = json_decode($json); // remove STD classes $json2array = json_decode(json_encode(

CakePHP 3 - Production site download file path issue

谁说我不能喝 提交于 2019-12-11 06:58:53
问题 In one of my controllers (Files), I have a download function as follows: public function download($id = null) { $latestDownload = $this->Files->find('all', ['order' => ['created' => 'DESC']])->first(); $filePath = WWW_ROOT. 'uploads/files'; //the uploads folder is a subdirectory of webroot; files is a subdirectory of uploads. $this->response->file($filePath . DS . $latestDownload->name, array('download' => true, 'name' => $latestDownload->name)); $this->set(compact('latestDownload')); } On my

Cakephp 3 case sensitive query

人盡茶涼 提交于 2019-12-11 06:08:48
问题 $date = date("Y-m-d"); $prev_date = date('m-d-Y', strtotime($date .' -1 day')); $q = "SELECT `id`, `external_id`, `status`, DATE_FORMAT(from_unixtime(`created`),'%m-%d-%Y') as crt, `extras` FROM `gshuplogs` WHERE DATE_FORMAT(from_unixtime(`created`),'%m-%d-%Y') = '$prev_date' and (BINARY `status` in ('success','DEFERRED') or `status` IS NULL)"; $conn = \Cake\Datasource\ConnectionManager::get('default'); $res = $conn->execute($q)->fetchAll('assoc'); debug($res);exit; The above query I have

Sending form via ajax in cakephp 3.4 with crsf and security components enabled

旧巷老猫 提交于 2019-12-11 05:59:23
问题 Need help, I want to be able to send a form via ajax to a controller for processing while the crsf and security components are enabled in the App controller (cakephp 3.4). Will appreciate any help I can get. Thanks 回答1: In order to send an ajax request you need to send the csrf token first through the head request as specified in the docs (link) Cakephp 3.6+ This is an example with a jquery ajax call $.ajax({ url: '<?php echo $this->Url->build(['controller' => 'Foo', 'action' => 'bar'])?>',

Core.php in cakephp 3

只愿长相守 提交于 2019-12-11 05:56:25
问题 I used to do some config with "routing.prefix" in cakephp2. It was in the file core.php. I notice there is no core.php in Cakephp 3. What is the equivalent of core.php in cake 3. 回答1: the core configuration file for cake3 is config/app.php http://book.cakephp.org/3.0/en/development/configuration.html but the routes go in the config/routes.php file http://book.cakephp.org/3.0/en/development/routing.html so If you want to have a named routing put it in routes.php http://book.cakephp.org/3.0/en

CakePHP 3, Count / Group Find Result?

此生再无相见时 提交于 2019-12-11 04:30:52
问题 UPDATE I have been playing around with pure SQL in phpMyAdmin, and think I have an answer, I would like someone to give it a look over to see if there are any problems with the query itself. Also I am not sure what the best way to proceed is, I know with Doctrine (Symfony) its easy to drop down to run an SQL query. I know it should be possible to do so with CakePHP, but would it be better to build the query with the query builder? SQL Query : SELECT userlevel_id AS userlevelID, COUNT( * ) AS