cakephp-3.0

Cakephp 3.0.0-RC2 I18n::locale() doesn't works

丶灬走出姿态 提交于 2019-12-11 13:15:59
问题 I am using Cakephp 3.0.0-RC2. It work's fine but I can't change du language of the user at login. My login function doesn't work. It do nothing : public function login() { if ($this->request->is('post')) { $user = $this->Auth->identify(); if ($user) { $this->Auth->setUser($user); I18n::locale($user['lang']); return $this->redirect($this->Auth->redirectUrl()); } $this->Flash->error(__("Nom d'utilisateur ou mot de passe incorrect, essayez à nouveau.")); } } Notice that when I change the

How to access a controller action from within another controllers action?

六眼飞鱼酱① 提交于 2019-12-11 12:59:59
问题 I'm trying to make an API Client with CakePHP 3.0. I'm using Http Client (http://book.cakephp.org/3.0/en/core-libraries/httpclient.html) to make all the requests but I don't need to use a database so at least for now I don't need Models. Suppose you have: UsersController CarsController Now from CarsController I want to get (from an API) all the users (using a method into UsersController). How can I access UsersController from CarsController using CakePHP 3.0? All the docs I read are just for

Reset an entity (or create a new empty entity) in controller after saving

百般思念 提交于 2019-12-11 12:49:35
问题 How do you reset an entity after saving it if there is not a redirect after saving (if you stay on the same action/page)? Example: I have a page listing all users. On the same page there is the form to add a new user. public function index() { $this->set('listallusers', $this->Users->find('all')); $user = $this->Users->newEntity(); if ($this->request->is('post')) { $user = $this->Users->patchEntity($user, $this->request->data ); if ( $this->Users->save($user) ) { $this->Flash->succeed('User

How to make imported/aliased names in AppController available to all controllers?

不羁岁月 提交于 2019-12-11 12:37:07
问题 I'm trying to add use Cake\ORM\TableRegistry in AppController to it can be used in all controllers, so there is no need to add it in each one. Is it possible? i've tried this <?php namespace App\Controller; use Cake\Controller\Controller; use Cake\ORM\TableRegistry; <------ want to add this class AppController extends Controller { public function initialize() { parent::initialize(); $this->loadComponent('Flash'); $this->loadComponent('ConfigsComp'); } } But i get this error: Error: Class 'App

Preventing malicious users update data at add action

半城伤御伤魂 提交于 2019-12-11 12:36:34
问题 Here is a basic add action: public function add() { $article = $this->Articles->newEntity(); if ($this->request->is('post')) { $article = $this->Articles->patchEntity($article, $this->request->data); if ($this->Articles->save($article)) { $this->Flash->success('Success.'); return $this->redirect(['action' => 'index']); } else { $this->Flash->error('Fail.'); } } $this->set(compact('article')); } If a malicious user injects at form a field with name id and set the value of this field to 2 .

CakePHP 3 Fetch associated data recursive

孤街醉人 提交于 2019-12-11 11:55:35
问题 I am trying to fetch Data in a recursive-way (over associations) using CakePHP 3.1 In Cake 3 I can use the "contain" key to fetch the next level of asociated data. But I need to fetch one more level. Does anyone know how to do this? I read the docs but didn't found anything there, with google it's the same. The 3 Levels are connected like this: OperationalCostInvoice (belongsTo Object) -> Object (hasMany OperationalCostTypes) -> OperationalCostType With OperationalCostInvoice->get($object_id,

Infinite Login Loop after CakePHP 3.6 update

本小妞迷上赌 提交于 2019-12-11 11:54:04
问题 in my application, based on CakePHP, I'm using. When I'm logging in using the URL /manager/login (corresponding to LoginController, Managerr prefix) everything is OK. When I logout or I use /manager the result is the following: /manager/login?redirect=%2Fmanager%2Flogin%3Fredirect%3D%252Fmanager%252Flogin%253Fredirect%253D%25252Fmanager%25252Flogin%25253Fredirect%25253D%2525252Fmanager%2525252Flogin%2525253Fredirect%2525253D%252525252Fmanager%252525252Flogin%252525253Fredirect%252525253D

How to sort external fields using Paginator in CakePHP 3

六眼飞鱼酱① 提交于 2019-12-11 11:44:23
问题 I'm developing an application using cakephp 3.0. I'm wondering if the paginator allows to sort fields coming from other tables which are included in the 'contain' clause. For example I have this statement: $this->paginate = [ 'contain' => ['Actors'] ]; The table 'Actors' contains the field 'description'. Is it possible to sort by the description field of the table Actors? I tried to specify the field using the dot notation: $this->Paginator->sort('Actors.description', __('Description')) as

Post multipart/data with Postman to Cakephp

跟風遠走 提交于 2019-12-11 10:41:29
问题 I'm currently building a RESTful API in Cakephp 3. I'm trying to upload a file (with some additional data) through form-data in the Postman chrome extension. However, I'm not really sure how I can obtain the data that is received through the request. Postman form-data This is the data that I try to send to the pictures controller in the api folder with the following code: public function add(){ debug($this->request->data); $picture = $this->Pictures->newEntity($this->request->data); if ($this

In Cakephp 3, Use another (not users but members) controller for login

左心房为你撑大大i 提交于 2019-12-11 10:31:04
问题 I am using Cakephp 3 for building new application where user have to login for their account however I am hitting the login URL http://localserver.com/members/login and it redirects me to http://localserver.com/users/login Look like the 'users' controller is set by default in Auth component. How can I override the default controller from 'users' to 'members'? NOTE: The URLs are not LIVE as I am working on my local-server. 回答1: Yes, this is related to the userModel config key, which defaults