cakephp-3.1

Confusing Validation vs. Application Rules in CakePHP3

蓝咒 提交于 2019-12-03 13:09:55
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 do it the right way. I also know there is currently a issue/discussion at GitHub about the Validation in CakePHP3 which may address the same topic. Validation errors are triggered e.g. with patchEntity. So I would think it is better to ALWAYS check/display errors BEFORE doing the save action: // src/Controller/UsersController.php public function

Intervention Image: Save image directly from an url with original file name and ext?

谁都会走 提交于 2019-12-03 02:29:38
How to get the filename, when taking image from a remote server? And how to save with original size and filename? // Take remote image $img = Image::make('http://image.info/demo.jpg'); // how to save in the img/original/demo.jpg $img->save(????); I use Intervention, ( http://image.intervention.io/api/make ) to build CakePHP 3 image Behavior, I want to provide an easy uploading from remote servers, and keep the original image as a source for future manipulation. EDIT I ask, is there the Intervention Image method that returns the name of the file, when taken from the remote server. I know php

cakephp3 session deprecated

半城伤御伤魂 提交于 2019-12-02 05:04:19
问题 I have update into my project the last version of cakephp core. Now I get this error: Deprecated (16384): SessionHelper has been deprecated. Use request->session() instead. [CORE/src/View/Helper/sessionHelper.php, line 39] The error I think is in this line: if ($this->session->read('admin_logged_in')){ What should I use instead? Thanks 回答1: if ($this->request->session->read('admin_logged_in')){ should be fine. UPDATE As per the comment of @raph below the correct answer is $this->request-

cakephp3 session deprecated

依然范特西╮ 提交于 2019-12-02 02:21:01
I have update into my project the last version of cakephp core. Now I get this error: Deprecated (16384): SessionHelper has been deprecated. Use request->session() instead. [CORE/src/View/Helper/sessionHelper.php, line 39] The error I think is in this line: if ($this->session->read('admin_logged_in')){ What should I use instead? Thanks raph if ($this->request->session->read('admin_logged_in')){ should be fine. UPDATE As per the comment of @raph below the correct answer is $this->request->session()->read('admin_logged_in') Note the () after session In Cakehp 3.7, use getSession() instead. $this

Subqueries in CakePHP 3?

此生再无相见时 提交于 2019-12-01 22:03:43
I have two tables products and product_categories that are associated through a third table, products_categories_products , according to CakePHP BelongsToMany conventions (Edit: these associations are established in ProductsTable.php and ProductCategoriesTable.php ). I want to generate a list of product categories, using the image from the best selling products to represent each category. I can achieve my desired outcome using the following function: public function findImages(Query $query, array $options) { $query->select([ 'ProductCategories.id', 'ProductCategories.name', 'ProductCategories_

Respond as XML not working since cakePHP 3.1

陌路散爱 提交于 2019-11-29 16:56:04
I need to render an XML+XSL template in my application, and it used to work with cakePHP 3.0. I have made the switch to 3.1 recently and it has stopped working. The problem is that I was having a formatted view of my XML, while now I just get a plain string. The migration guide says something about some changes in the RequestHandlerComponent , but nothing helpful (or maybe it's just me and I don't get the point :)). This is my controller (it is exactly as it was with Cake3.0): <?php namespace App\Controller; use App\Controller\AppController; use Cake\Utility\Xml; use Cake\Event\Event; use Cake

CakePHP 3 changing the radio input template

☆樱花仙子☆ 提交于 2019-11-29 04:44:07
Cakephp 3 create a radio container with label -> input like that <div class="radio"> <label class="radio-acces-checked" for="condition-access-1"> <input id="condition-access-1" type="radio" value="1" name="condition_access"> Free access </label> </div> ... I would like change structure but it does not work, it's always the same strucure... Do you have an idea about how to solve my problem ? $myTemplates = [ 'radioWrapper' => '<div class="radio">{{label}}{{input}}</div>' ]; echo $this->Form->radio('condition_access', [ ['value' => 1, 'text' => __('Free Access')], ['value' => 2, 'text' => __(

Respond as XML not working since cakePHP 3.1

梦想与她 提交于 2019-11-28 10:33:19
问题 I need to render an XML+XSL template in my application, and it used to work with cakePHP 3.0. I have made the switch to 3.1 recently and it has stopped working. The problem is that I was having a formatted view of my XML, while now I just get a plain string. The migration guide says something about some changes in the RequestHandlerComponent , but nothing helpful (or maybe it's just me and I don't get the point :)). This is my controller (it is exactly as it was with Cake3.0): <?php namespace