cakephp-3.0

How to create a `IN` clause in CakePHP query?

蓝咒 提交于 2019-11-27 23:06:04
How do you make it where in clause in new CakePHP? I'm trying: $restaurants->find()->where(['id' => $r_ids])->all(); Where $r_ids is array of ids I need in my query, but this doesn't work as expected. With CakePHP 3.x it's now necessary to either indicate the data type, which for an array of values need to have [] appended to the type: $query = $articles ->find() ->where(['id' => $ids], ['id' => 'integer[]']); or to explicitly make use of the IN keyword: $query = $articles ->find() ->where(['id IN' => $ids]); See also Cookbook > Database Access & ORM > Query Builder > Automatically Creating IN

CakePHP 3: Missing route error for route that exists

我的梦境 提交于 2019-11-27 18:12:53
问题 CakePHP 3.0 I'm getting a "Missing Route" error for a route that exists. Here are my routes: #my admin routes... Router::prefix('admin', function($routes) { $routes->connect('/', ['controller'=>'Screens', 'action'=>'index']); $routes->connect('/screens', ['controller'=>'Screens', 'action'=>'index']); $routes->connect('/screens/index', ['controller'=>'Screens', 'action'=>'index']); //$routes->fallbacks('InflectedRoute'); }); Router::scope('/', function ($routes) { $routes->connect('/login', [

Conditions to paginate for belongsToMany CakePHP 3

放肆的年华 提交于 2019-11-27 16:45:08
问题 I have the tables Semesters, Disciplines and a jointTable Semesters_Disciplines. I want to create a action index in DisciplinesController with a semester_id as parameter, which list with paginate just the disciplines what belongs to the semester with the id passed in the parameter. I tried this: public function index($semester_id) { $options = ['semester_id' => $semester_id]; $this->paginate = ['conditions' => $options]; $this->set('disciplines', $this->paginate($this->Disciplines)); $this-

Responsive bootstrap designing in CakePHP 3x

為{幸葍}努か 提交于 2019-11-27 16:12:24
问题 As CakePHP 3x has inbuilt responsive feature, I would like to know the element structures and class definitions. I'm indeed familiar with Twitter Bootstrapping ( done in cake 2x projects). But need to familiarize with CakePHP 3x version, as its new in framework! I looked into css/base.css and found few classes for elements, like Grids: .small-1(to 12), .medium-1(to 12), .large-1(to 12) Offsets: .small-offset-1(to 12), .medium-offset-1(to 12), .large-offset-1(to 12) Align: .left, .right....

What means Call to a member function on boolean and how to fix

天大地大妈咪最大 提交于 2019-11-27 15:07:54
I'm new with cakePHP 3. I have created a controller and model where I call a function to get all users from the database. But when I run the code below I will get the following error "Call to a member function get_all_users() on boolean" . what does this error means and how can I fix this up? User.php (model) namespace App\Model\Entity; use Cake\ORM\Entity; class User extends Entity { public function get_all_users() { // find users and return to controller return $this->User->find('all'); } } UsersController.php (controller) namespace App\Controller; use App\Controller\AppController; class

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

会有一股神秘感。 提交于 2019-11-27 14:07:02
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 on my drop-down: <option value="10">Fabian;Pankiers</option> See I need a result without the semicolon

Cakephp 3.5.6 disable CSRF Middleware for controller

☆樱花仙子☆ 提交于 2019-11-27 07:17:02
问题 I'm trying to disable the CSRF check for a single controller (API), but I'm unable to find how I'm able to achieve this. The pre 3.5.0 CSRF Component had the ability to be disabled on certain request using: $this->eventManager()->off($this->Csrf); 回答1: There are two ways to do that. Apply the middleware to specific routing scopes (or even routes) Depending on what routes you create, you can apply the middleware to specific scopes only, for example: // config/routes.php use Cake\Http

How do you modify a UNION query in CakePHP 3?

六眼飞鱼酱① 提交于 2019-11-27 06:57:50
问题 I want to paginate a union query in CakePHP 3.0.0. By using a custom finder, I have it working almost perfectly, but I can't find any way to get limit and offset to apply to the union, rather than either of the subqueries. In other words, this code: $articlesQuery = $articles->find('all'); $commentsQuery = $comments->find('all'); $unionQuery = $articlesQuery->unionAll($commentsQuery); $unionQuery->limit(7)->offset(7); // nevermind the weirdness of applying this manually produces this query:

DefaultPasswordHasher generating different hash for the same value

爱⌒轻易说出口 提交于 2019-11-27 06:13:07
问题 I have a password stored at database hashed with DefaultPasswordHasher at add action. I have another action for change the password for the loggedin user, on this form I have a field called current_password that I need compare with the current password value from database . The issue is that DefaultPasswordHasher is generating a different hash for each time that I'm hashing the value of the form so this will never match with the hash from database. Follow the validation code of the 'current

Login [ Auth->identify() ] always false on CakePHP 3

北城以北 提交于 2019-11-27 05:59:04
问题 I started using CakePHP 3 after a time using CakePHP 2 and I am having troubles to create the authentication login. The new auth function $this->Auth->identify() always return false. On the database, the password are encrypted perfect and the query who takes the user it's ok too. My code: AppController: [...] class AppController extends Controller{ public function initialize(){ $this->loadComponent('Flash'); $this->loadComponent('Auth', [ 'loginRedirect' => [ 'controller' => 'Admin', 'action'