cakephp-3.0

Encryption/Decryption of Form Fields in CakePHP 3

穿精又带淫゛_ 提交于 2019-11-27 05:13:07
I want to have some form-fields encrypted when they are added/edited and decrypted when they are looked up by cake. Here is the code that works for me in v2.7.2: core.php Configure::write('Security.key','secretkey'); app/model/patient.php. public $encryptedFields = array('patient_surname', 'patient_first_name'); public function beforeSave($options = array()) { foreach($this->encryptedFields as $fieldName){ if(!empty($this->data[$this->alias][$fieldName])){ $this->data[$this->alias][$fieldName] = Security::encrypt( $this->data[$this->alias][$fieldName], Configure::read('Security.key') ); } }

Pagination Sort in Cakephp 3.x

社会主义新天地 提交于 2019-11-27 03:38:28
问题 In cakephp 3.x i can't do paginate order in a find This is my controller: //AgentsController.php public function show() { $agents = $this->Agents->find() $this->set('agents', $this->paginate($agents)); } And here part of my view //show.ctp <!-- ....... --> <table class="table table-striped"> <thead> <tr> <th> <?php echo $this->Paginator->sort('full_name', 'Nome', array('escape' => false)); ?> </th> <th> <?php echo $this->Paginator->sort('username', 'Email', array('escape' => false)); ?> </th>

How to safely use reserved SQL names?

你离开我真会死。 提交于 2019-11-27 02:18:26
I'm using Cakephp 3 using sqlserver as datasource server. I am sure there's no problem with my database connection.. as home.ctp prompts that I am connected to my database.. and I'm as well using migrations plugin to create my tables.. it seems like there is no problem working with these tools. but after I bake my MVC, I only got page full of errors.. for example $bin\cake bake all tests there are no errors I found and MVC are in its specific folder, testController.php, testTable, etc. and in browsers localhost:8765\tests but all I got is page of different errors.. Im seeing Error: SQLSTATE

How can I use my own external class in CakePHP 3.0?

核能气质少年 提交于 2019-11-27 00:38:43
问题 I am creating an application in CakePHP 3.0, in this application I want to draw SVG graphs of data using a php class that I have written. What would be the proper way to go about using this class in my CakePHP 3 project? More specifically: What are the naming conventions? Do I need to use a specific namespace? Where do I put the file that contains the PHP class? How can I include it and use it in a controller or a view? 回答1: What are the naming conventions? Do I need to use a specific

CakePHP 3 time column gets date added

我是研究僧i 提交于 2019-11-26 22:26:25
问题 I have a number of columns defined in my MySQL database as "time". That is, they have a time, but not a date. When they are read by the CakePHP 3 ORM, they are being converted into Cake\I18n\Time objects (through the Cake\Database\Type\TimeType class), but the result always has both a date and a time in it, with the date set to the current date. For example, if the value is "20:00:00", debug($record['start_time']) will generate: object(Cake\I18n\Time) { 'time' => '2015-06-21T20:00:00+0000',

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

好久不见. 提交于 2019-11-26 21:23:00
问题 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. 回答1: 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() -

CakePHP 3.0 -> Between find condition

≡放荡痞女 提交于 2019-11-26 19:02:58
Is it possible to do a "BETWEEN ? AND ?" where condition LIKE in cakephp 2.5? In cakephp 2.5 I write something like 'conditions' => ['start_date BETWEEN ? AND ?' => ['2014-01-01', '2014-12-32']] how can I migrate that? additionally I would write something like 'conditions' => [ '? BETWEEN start_date AND end_date'] => '2014-03-31'] Expressions Between expression are supported out of the box, however they only support the first case without additional fiddling: $Query = $Table ->find() ->where(function($exp) { return $exp->between('start_date', '2014-01-01', '2014-12-32', 'date'); }); If you'd

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

时光总嘲笑我的痴心妄想 提交于 2019-11-26 18:29:07
问题 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'); } }

Why are date/time values interpreted incorrectly when patching/saving?

耗尽温柔 提交于 2019-11-26 16:45:46
I try to save data from a cakephp 3 form. All data are well saved but datetime not. I've got 2 datetime fields. Those fields are filled by jquery-ui widget. The problem seems to happened when pacthing entity. $intervention = $this->Interventions->patchEntity($intervention, $this->request->data); Debug of $this->request->data : 'user_id' => '1', 'description' => 'test', 'starttime' => '2015/11/15 10:00', 'endtime' => '2015/11/15 12:10' Debug of my object $intervention after pacthEntity : object(App\Model\Entity\Intervention) 'id' => (int) 3, 'user_id' => (int) 1, 'description' => 'test',

How to limit contained associations per record/group?

一笑奈何 提交于 2019-11-26 13:44:21
I have a Model, Articles, which hasMany Abstracts. I want to load the 10 latest Articles, and for each Article, the Abstract with the highest number of points. My function looks like this: public function getArticles($category, $viewName) { $subArticles = $this->Articles->findByCategory($category)->contain([ 'Abstracts' => function ($q) { return $q ->select(['body', 'points', 'article_id']) ->where(['Abstracts.approved' => true]) ->limit(10) ->order(['Abstracts.points' => 'DESC']); } ]) ->limit(10) ->order(['Articles.created' => 'DESC']) ; $this->set( $viewName . 'Articles', $subArticles ); }