cakephp-3.0

How to prevent showing/receiving untranslated content?

喜你入骨 提交于 2020-01-07 03:48:29
问题 This is my Distance Cell public function display() { $this->loadModel('Distances'); $distances = $this->Distances->find('all',[ 'order' => 'Distances.id ASC', ])->toArray(); $this->set('distances',$distances); }} Problem, if content is not yet translated and stored in db, original untranslated content is displayed on the page. How to prevent this, and show only translated content in current language? 回答1: The onlyTranslated option This is unfortunately not documented yet, but the Translate

I need to count the today created account in Cake 3

馋奶兔 提交于 2020-01-06 16:11:07
问题 I need to count the users, but my condition is only if their account have been created today. I have a users table with a created field (datetime) for each rows. How can i do it in Cakephp, i didn't find the answer in the documentation. $usersNewCount = Number::format($this->Users->find()->where(['created' => 'CURDATE()'])->count()); I tried with CURDATE, and of course it's not working, i guess Cakephp has a specific function for te datetime field ? 回答1: What you are doing there won't work

CakePHP 3.x: how to extend the Request class

杀马特。学长 韩版系。学妹 提交于 2020-01-06 15:14:34
问题 I have a plugin and I wish to extend the Request class ( Cake\Network\Request ), to add new methods and properties that can be used by the controllers of my plugin. How to do? Thanks. 回答1: Create your extended request class and simply pass an instance of it to the dispatcher in your apps webroot/index.php front controller: https://github.com/cakephp/app/blob/3.0.0/webroot/index.php#L35 // .... use App\Network\MyCustomRequest; $dispatcher = DispatcherFactory::create(); $dispatcher->dispatch(

CakePHP 3.x: how to extend the Request class

故事扮演 提交于 2020-01-06 15:14:17
问题 I have a plugin and I wish to extend the Request class ( Cake\Network\Request ), to add new methods and properties that can be used by the controllers of my plugin. How to do? Thanks. 回答1: Create your extended request class and simply pass an instance of it to the dispatcher in your apps webroot/index.php front controller: https://github.com/cakephp/app/blob/3.0.0/webroot/index.php#L35 // .... use App\Network\MyCustomRequest; $dispatcher = DispatcherFactory::create(); $dispatcher->dispatch(

Issue in hasMany associated model data update/modify

我们两清 提交于 2020-01-06 06:11:40
问题 I have two table, categories hasMany products id name active products belongsTo categories id name category_id active When I am editing the categories, in the same time I am also displaying the Products related to the category so that I can update/modify products related to the category. Issue:- When I add more products for the category that works fine but when I remove some products from the category,the removed product does not get deleted from the database. So I want to know that This

Issue in hasMany associated model data update/modify

北慕城南 提交于 2020-01-06 06:11:12
问题 I have two table, categories hasMany products id name active products belongsTo categories id name category_id active When I am editing the categories, in the same time I am also displaying the Products related to the category so that I can update/modify products related to the category. Issue:- When I add more products for the category that works fine but when I remove some products from the category,the removed product does not get deleted from the database. So I want to know that This

Cakephp 3 - belongsToMany with _joinData

白昼怎懂夜的黑 提交于 2020-01-05 08:06:00
问题 I try to realize a bolongsToMany association with additional data in the join table. The join table has columns for the foreign keys and an additional column 'context' articlesController: $article = $this->Articles->patchEntity($article, $this->request->getData()); debug($article);die; and in a Plugin-Behavior: public function beforeMarshal(Event $event, ArrayObject $data, ArrayObject $options) { $data['Categories.Categories'] = ['id' => '1', '_joinData' => ['context' => 'Tag']]; debug($data)

Cakephp 3 - belongsToMany with _joinData

荒凉一梦 提交于 2020-01-05 08:04:33
问题 I try to realize a bolongsToMany association with additional data in the join table. The join table has columns for the foreign keys and an additional column 'context' articlesController: $article = $this->Articles->patchEntity($article, $this->request->getData()); debug($article);die; and in a Plugin-Behavior: public function beforeMarshal(Event $event, ArrayObject $data, ArrayObject $options) { $data['Categories.Categories'] = ['id' => '1', '_joinData' => ['context' => 'Tag']]; debug($data)

Cakephp 3 - belongsToMany with _joinData

走远了吗. 提交于 2020-01-05 08:04:15
问题 I try to realize a bolongsToMany association with additional data in the join table. The join table has columns for the foreign keys and an additional column 'context' articlesController: $article = $this->Articles->patchEntity($article, $this->request->getData()); debug($article);die; and in a Plugin-Behavior: public function beforeMarshal(Event $event, ArrayObject $data, ArrayObject $options) { $data['Categories.Categories'] = ['id' => '1', '_joinData' => ['context' => 'Tag']]; debug($data)

CakePHP 3.x dynamic finder method

和自甴很熟 提交于 2020-01-05 04:55:09
问题 I have this problem with a CakePHP 3 application I am trying to get a category by it's slug and all related articles belonging to that category. I am using dynamic finder method findBySlug in the Controller but it throws an error in the view. Here is my code: public function view($slug = null) { if (!$slug) { throw new NotFoundException(__('Invalid category slug')); } $category = $this->Categories->findBySlug($slug, [ 'contain' => [ 'Articles' ] ]); $this->set(compact('category')); } and the