cakephp-3.0

How to append to a CakePHP3 ResultSet?

好久不见. 提交于 2019-12-13 08:46:27
问题 I have a query (a Query object): $joblineitems = $this->JobLineItems->find('all'); It has results (a ResultSet object): $joblineitemsresults = $joblineitems->all(); The ResultSet object is an Iterable such that a foreach() loop will return each of the JobLineItem objects. I simply want to add an additional result to $joblineitemsresults - specifically I want to append a $this->JobLineItems->newEntity() to the end of the results so that when I subsequently paginate $joblineitemsresults and

Cakephp 3.x update a record without form

自闭症网瘾萝莉.ら 提交于 2019-12-13 07:58:41
问题 In my users/index page I basically list every user in the users table by doing the following: <?php foreach ($users as $user): ?> <tr> <td><?= h($user->name) ?></td> <td><?= h($user->email) ?></td> <td><?= h($user->phone_nr) ?></td> <td><?= h($user->role)?></td> </tr> <?php endforeach; ?> User.role field is an enum type with two choices: 'user' or 'admin' . Instead of just listing the user's role, I need to have a dropdown to be able to change it right away. So basically I need something like

how to only pick the first many-to-many record and have it as a separate relation?

馋奶兔 提交于 2019-12-13 07:56:22
问题 My Tables are as follows: EventTicketSales belongsToMany Approvings via EventTicketSalesApprovings . Inside EventTicketSalesTable.php I wrote $this->belongsToMany('Approvings', [ 'className' => 'Contacts', 'joinTable' => 'event_ticket_sales_approvings', 'targetForeignKey' => 'contact_id', 'saveStrategy' => 'replace', ]); When I do pagination, I write $contain = [ 'Approvings' ]; $sales = $this->paginate($this->EventTicketSales->find()->where($conditions)->join($join)->contain($contain));

How to use table name different then in database in cake php 3

你说的曾经没有我的故事 提交于 2019-12-13 07:32:00
问题 I am using cake php 3.4. I have guest and country table in database. I want to access these table object as Guests and Contries. I want to use like this : $this->Guests->find(); instead of $this->Guest->find() 回答1: You have to create a model GuestsTable.php in src/Model/Table/ namespace App\Model\Table; use Cake\ORM\Table; class GuestsTable extends Table { public function initialize(array $config) { $this->setTable('guest'); // your table name // Prior to 3.4.0 // $this->table('guest'); } }

CakePHP - Controller testing failed because of Security component

匆匆过客 提交于 2019-12-13 07:14:01
问题 I am trying to test controller methods (add, edit, ...) that use Security component. ContactsController public function initialize() { $this->loadComponent('Security'); } public function add() { $contact = $this->Contacts->newEntity(); if ($this->request->is('post')) { $contact = $this->Contacts->patchEntity($contact, $this->request->data); if ($this->Contacts->save($contact)) { $this->Flash->success(__d('contact_manager', 'The contact has been saved.')); return $this->redirect(['action' =>

cakephp 3.1 input field with european date format

自闭症网瘾萝莉.ら 提交于 2019-12-13 07:03:05
问题 I have a table with records of users (name, forename, birthdate, etc.) and I want to find users by name or birthdate or every possible combination of this. My code works well, but the birthdate is stored in the american format (YYYY-MM-dd), so I have to search after dates in this format to get the right record. That´s really annoying, because in Germany we use the european format (dd.MM.YYYY) and I want to search for the dates by our habitual format. Now I need help to give the input field

CakePHP3 - Upload image file

强颜欢笑 提交于 2019-12-13 05:54:07
问题 I am new in cakephp3. I have an Employee Table and I want to save an image path. Below is my form in add.ctp <?php echo $this->Form->create($employee, ['enctype' => 'multipart/form-data']); ?> <fieldset> <legend><?= __('Add Employee') ?></legend> <?php echo $this->Form->input('image_path', ['type' => 'file']); echo $this->Form->input('first_name'); echo $this->Form->input('last_name'); echo $this->Form->input('birthday', array( 'type' => 'date', 'label' => 'Birthday', 'dateFormat' => 'MDY',

CakePHP wrong date in MySQL

懵懂的女人 提交于 2019-12-13 05:22:59
问题 I had a field called issue_date in a table that was datetime type in MySQL and I changed to date. When I am trying to save the date to the database is saving it with weird years(for example 2196), when the real date is 2003, I made an output of the object before saving it and is showing the real date (2003-06-30) The field is issue_date . This is my function to save: public function populate(){ $this->tangoModel=$this->loadModel('Tango'); $tango=$this->tangoModel->getInvoices(); $this-

Where is the log file after enabling query logging?

我怕爱的太早我们不能终老 提交于 2019-12-13 05:21:25
问题 I followed the instructions to enable query logging in cakephp v3. http://book.cakephp.org/3.0/en/orm/database-basics.html#query-logging // Turn query logging on. $conn->logQueries(true); // Turn query logging off $conn->logQueries(false); use Cake\Log\Log; // Console logging Log::config('queries', [ 'className' => 'Console', 'stream' => 'php://stderr', 'scopes' => ['queriesLog'] ]); // File logging Log::config('queries', [ 'className' => 'File', 'path' => LOGS, 'file' => 'queries.log',

Can't submit form using create();

瘦欲@ 提交于 2019-12-13 04:52:34
问题 So i have this method inside of my: JobsController.ctp: <?php namespace App\Controller; use App\Controller\AppController; use Cake\ORM\TableRegistry; /** * Jobs Controller * * @property \App\Model\Table\JobsTable $Jobs */ class JobsController extends AppController { public $name = 'Jobs'; public function add() { //Some Vars assigning skipped, var job is empty $this->set('job','Job'); $this->Job->create(); } } And I have this view with the form itself: add.ctp: <?= $this->Form->create($job); ?