cakephp-3.0

CakePHP 3 Saving BelongsToMany Association Unknown type “” Error

邮差的信 提交于 2019-12-07 11:27:30
问题 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

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

故事扮演 提交于 2019-12-07 09:56: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'), ]); 回答1: 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

Deleting Records From Associated Table With PatchEntity in CakePHP

安稳与你 提交于 2019-12-07 07:53:28
I have a CakePHP model where a Job hasmany Employees and an Employee belongsTo a Job. The View I use to edit both Jobs and Employees is a Job view. Here is code from my Job Controller: $job = $this->Jobs->get($id, [ 'contain' => ['Employees'] ]); if ($this->request->is(['patch', 'post', 'put'])) { $req = $this->request->data; $job = $this->Jobs->patchEntity($job, $req, [ 'validate' => false, 'associated' => ['Employees'] ]); $saveResult = $this->Jobs->save($job, [ 'validate' => false, 'associated' => ['Employees'] ]); $this->request->data looks like this: 'employees' =>[ 0 => [ 'id' => 1, ...

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

℡╲_俬逩灬. 提交于 2019-12-07 07:29:01
问题 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 回答1: I would do this in the validator of your UsersTable. src/Model/Table/UsersTable.php $validator ->notEmpty('current_password') ->add('current_password

Class 'Locale' not found issue on CakePHP 3

﹥>﹥吖頭↗ 提交于 2019-12-07 04:01:10
问题 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. 回答1: 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

Cakephp 3.x Sorting of another model is not working

前提是你 提交于 2019-12-07 02:30:16
问题 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 = [

cakephp 3 displaying date without time

…衆ロ難τιáo~ 提交于 2019-12-06 21:20:57
问题 CakePHP 3: I have a database field which is a DATE (not DATETIME nor TIMESTAMP) When I display echo $contact->date; It will show something like 2014. 01. 06. 0:00 . How to hide hours and minutes? I tried print $this->Time->format($contact->date, 'Y-m-d'); but I got 2014-0-6 How to get year-month-day? rrd 回答1: Have you tried this? echo $contact->date->format('Y-m-d'); 回答2: add in App\Controller: use Cake\I18n\Time; Time::$defaultLocale = 'es-ES'; Time::setToStringFormat('YYYY-MM-dd'); 回答3: If

Update only one field on Cakephp 3

江枫思渺然 提交于 2019-12-06 19:55:07
问题 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? 回答1: 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

Cakephp 3 Unable to mark multiple checkboxes selected

你离开我真会死。 提交于 2019-12-06 15:33:51
My Edit view file has a set of checkboxes. I have managed to retrieve the selected checkbox values from the database, and want to mark these as selected in the view file. Edit view file <div class="col-md-12"> <?= $this->Form->label('category','Pick Categories');?> <?= $this->Form->select('category', $options,['multiple'=>'checkbox', 'required'=>'false', 'label'=>'Category','class'=>'col-md-12','selected'=>$catSel]); ?> </div> $options is $options = ['A'=>'Val1', 'B'=>'Val2', 'C'=>'Val3', 'D'=>'Val4', 'E'=>'Val5']; $catSel has been set in my controller and is returning the correct values. I

CakePHP 3- Showing all error and buildRules messages in controller

泪湿孤枕 提交于 2019-12-06 12:47:32
问题 I have this Model/Table/UsersProfilesTable.php where I have specified all the error messages and buildRules. My intention is to list all the validation errors in the controller while attempting to save the data. The code is mentioned below. // Model/Table/UsersProfilesTable.php class UserProfilesTable extends Table{ public function validationDefault(Validator $validator){ $validator = new Validator(); $validator ->notEmpty("first_name","First name cannot be empty.") ->requirePresence("first