cakephp-3.0

How to add a field in database table by cakephp migration?

亡梦爱人 提交于 2019-12-05 19:06:20
I am very new in cakephp version 3. Here I am trying to use migration plugin. I have already created a table by using below command => cake bake migration CreateUsers name : string It's worked very fine, now I am trying to add a field in here so I have written => cake bake migration add age:int to Users It's not working. How can I add this field by migration using shall command ?May you help me please ? A syntax like add column:type to table doesn't exist, so that's why you are seeing what you're seeing. The correct syntax for adding columns is AddColumnNameToTableName column:type where the

CakePHP 3: find() with cache

人盡茶涼 提交于 2019-12-05 18:55:51
About the get() method, I read here : Like find() get has caching integrated. You can use the cache option when calling get() to perform read-through caching But later, in the section dedicated to the find() method ( here ), the cache is not mentioned, there are no examples for the cache and the cache option is not mentioned among the supported options. So I would like to know: can I use the cache option with the find() method? If so, how? Thanks. Thanks to ndm. So: $query = $this->Pages->find('all'); $query->cache('all_pages'); $this->set('pages', $query->all()); Or (more simple): $query =

CakePHP 3 Saving BelongsToMany Association Unknown type “” Error

烈酒焚心 提交于 2019-12-05 17:43:42
I've been banging my head against the wall trying to figure out why my Emails (belongsToMany Guests (belongsToMany Emails)) won't save. When I attempt to save the email model with associated data (guests) it fails at $this->Emails->save($email) with: Unknown type "" Error InvalidArgumentException I've followed the CakeBookmarks example ( http://book.cakephp.org/3.0/en/tutorials-and-examples/bookmarks/intro.html ) to the tee at this point for relationships and the edit form. And even built it and pulled code from it. Here's the relevant code from my project, any help or speculation is

Exclude specific cakephp controller from http basic auth

烂漫一生 提交于 2019-12-05 17:31:43
I'm trying to exclude a path (URI) from being blocked by basic http auth. The path is /rest ( http://example.com/rest ) and represents a controller of a cakephp 3 application. It is NOT a real file, but rather a path rewritten by a rewite-condition and handeled by index.php in the webroot dir. Here's the rewrite rules: /var/www/.htaccess : <IfModule mod_rewrite.c> RewriteEngine on RewriteRule ^$ webroot/ [L] RewriteRule (.*) webroot/$1 [L] </IfModule> /var/www/webroot/.htaccess : <IfModule mod_rewrite.c> RewriteEngine On RewriteCond %{REQUEST_FILENAME} !-d RewriteCond %{REQUEST_FILENAME} !-f

Cakephp 3 : How to get max amout row from a table

故事扮演 提交于 2019-12-05 16:41:42
I have table call users , like id name amount created 1 a 100 6-16-2016 2 b 200 5-16-2016 I need max amount full row, I have tried below code but getting syntax error. $user = $this->Users->find('all',[ 'fields' => array('MAX(Users.amount) AS amount'), ]); simplest way $user = $this->Users->find('all',[ 'fields' => array('amount' => 'MAX(Users.id)'), ]); using select instead of an options array $user = $this->Users->find() ->select(['amount' => 'MAX(Users.id)']); making use of cake SQL functions $query = $this->Users->find(); $user = $query ->select(['amount' => $query->func()->max('Users.id')

CakePHP 3.0 - Compare Database Password with the old password while changing password

↘锁芯ラ 提交于 2019-12-05 12:36:44
I am working on CakePHP 3.0 and I would like to compare the database password with the old password entered in the form in "Change Password" functionality. But I am not able to do so since the password is hashed and the hashed password is different every time even if we use the same password. Please help me in this. Thanks in advance, Melee I would do this in the validator of your UsersTable. src/Model/Table/UsersTable.php $validator ->notEmpty('current_password') ->add('current_password', 'custom', [ 'rule' => function($value, $context) { $query = $this->find() ->where([ 'id' => $context[

Class 'Locale' not found issue on CakePHP 3

回眸只為那壹抹淺笑 提交于 2019-12-05 08:18:42
I'm just downloaded the files from this link , extracted and tried execute but I had this error: Fatal error: Class 'Locale' not found in D:\xampp\htdocs\cake-3-beta-2\vendor\cakephp\cakephp\src\I18n\I18n.php on line 229 I'm running on localhost with xampp... I had the same issue with beta 1 and 2. Tijme I faced the same problem today. You need to enable the intl PHP extension in your PHP configuration ( .ini ). Solution Xampp (Windows) Open /xampp/php/php.ini Change ;extension=php_intl.dll to extension=php_intl.dll (remove the semicolon) Copy all the /xamp/php/ic*.dll files to /xampp/apache

Cakephp 3.x Sorting of another model is not working

十年热恋 提交于 2019-12-05 04:35:15
I have two models Users & Roles Here "Roles hasMany Users" and "Users belongsTo Roles" When the user saved we're also asking user's role & record saved. Problem : I have list of users with column firstname, lastname,roles. Each & Every column has sorting but on roles sorting is not working. Role Table contains "name" field for Role name. I have referred below link but it doesn't working for me. Pagination Sort in Cakephp 3.x UsersController: public function index() { $this->paginate = [ 'contain' => ['Roles'], 'conditions' => [ 'Users.user_type <>' => 1 ] ]; $this->set('users', $this->paginate

Update only one field on Cakephp 3

时间秒杀一切 提交于 2019-12-05 02:41:24
In some part of my app I need to update only the field is_active of some table with a lot of fields. What is the best approach to update only this field and avoid the validations and requiriments of all other fields? And if you want to update particular row only , use this: $users= TableRegistry::get('Users'); $user = $users->get($id); // Return article with id = $id (primary_key of row which need to get updated) $user->is_active = true; // $user->email= abc@gmail.com; // other fields if necessary if($users->save($user)){ // saved } else { // something went wrong } See here ( Updating data in

Pass extra data to finder auth

笑着哭i 提交于 2019-12-05 02:27:33
My finder from Auth has conditions that I need to access $this->request but I don't have access for that on UsersTable . AppController::initialize $this->loadComponent('Auth', [ 'authenticate' => [ 'Form' => [ 'finder' => 'auth', ] ] ]); UsersTable public function findAuth(Query $query, array $options) { $query ->select([ 'Users.id', 'Users.name', 'Users.username', 'Users.password', ]) ->where(['Users.is_active' => true]); // If i had access to extra data passed I would use here. return $query; } I need pass an extra data fom AppController to finder auth since I dont have acces to $this-