cakephp-3.0

CakePHP query closest latitude longitude from database

|▌冷眼眸甩不掉的悲伤 提交于 2019-11-30 12:21:34
In a CakePHP (v3) application, how can I retrieve the closest results based on passed lat lng values? I'd like to have them back as native CakePHP entities, so something like this: public function closest($lat, $lng) { $sightings = //records within given lat lng $this->set(compact('sightings')); $this->set('_serialize', ['sightings']); } I know this SQL works: SELECT *, ( 3959 * acos( cos( radians(50.7) ) * cos( radians( latitude ) ) * cos( radians( longitude ) - radians(-1.8) ) + sin( radians(50.7) ) * sin( radians( latitude ) ) ) ) AS distance FROM sightings HAVING distance < 10 ORDER BY

CakePHP 3 : Define global contant variable

时光怂恿深爱的人放手 提交于 2019-11-30 09:52:26
问题 I am working on CakePHP 3 project which is a little big. I want to keep my application as much clean as possible by separating all media files from core application and that's why I have to store all media files on a separate subdomain as media.myproject.com and the project is accessible from www.myproject.com . Also in media.myproject.com there could be many directories as /root |- users |- avatar |- cover |- services |- logo |- banner |- slides |- clients |- logo |- avatar |- etc |- etc |-

How to reduce the amount of fields for _joinData in Cake 3.x?

帅比萌擦擦* 提交于 2019-11-30 09:40:27
问题 Situation Using Cake 3.2.4 I have a EventTicketSales table that $this->belongsToMany('Approvings', [ 'className' => 'Contacts', 'joinTable' => 'event_ticket_sales_approvings', 'targetForeignKey' => 'contact_id', 'saveStrategy' => 'replace', ]); When I do a pagination like this: $this->paginate['contain'] = [ 'Approvings' => function (\Cake\ORM\Query $query) { return $query->select([ 'Approvings.id', 'Approvings.name', 'Approvings.company', 'EventTicketSalesApprovings.event_ticket_sale_id' ]);

List all controllers/actions in Cakephp 3

 ̄綄美尐妖づ 提交于 2019-11-30 07:06:11
How do I list all the controllers/actions on my site? Configure::listObjects('model') doesnt seem to exist anymore. I am trying to write a function to generate/add to the ACO's in my ACL setup. Thanks. MjGaiser So here is what I did. In my Resource Controller: Include the reflection class/method libraries use ReflectionClass; use ReflectionMethod; To get the controllers: public function getControllers() { $files = scandir('../src/Controller/'); $results = []; $ignoreList = [ '.', '..', 'Component', 'AppController.php', ]; foreach($files as $file){ if(!in_array($file, $ignoreList)) {

How to retrieve associations together with authenticated user data?

风格不统一 提交于 2019-11-30 05:58:26
问题 I have a Users table and a UsersProfiles table - the two are obviously related and the user table stores basic user_id , username , password while the users_profiles table stores firstname , lastname , job_title etc. In CakePHP 3, the call to Authentication Component on login returns the basic user table row. I would like to modify the same to also return the corresponding profile row. How can I do this? I found a way to do it - but am not sure if there is a more elegant or simpler way.

Save associations with Cakephp 3

狂风中的少年 提交于 2019-11-29 23:22:12
问题 I have a problem with CakePHP 3 and saving new entity and its associations with one operation. In my opinion I do it like recommended in the documentation. Here my controller: $articles = TableRegistry::get('Articles'); $article = $articles->newEntity($this->request->data); if ($this->request->is('post')) { $valid = $articles->validate($article, [ 'associated' => ['Topics'] ]); if ( $valid ) { $articles->save($article, [ 'validate' => false, 'associated' => ['Topics'] ]); } } Thats my models:

Mapping slugs from database in routing

徘徊边缘 提交于 2019-11-29 18:17:24
I have to support url friendly structure for a project. There is multiple tables with a slug column, in cakephp how can I route the slug to a controller in the most efficient way. At first I was checking if slug exist in a table, if slug exist use the route: $c = TableRegistry::get('cateogories'); $result= $c->find()->select(['id'])->where(['url'=>$slug])->toArray(); if(count($result) > 0) { $routes->connect( '/:slug', ['controller' => 'Categories', 'action' => 'index', 'id' => $result[0]['id']] ); } The problem being that I have multiple checks like the one above and each one is being ran

CakePHP 3 : Define global contant variable

社会主义新天地 提交于 2019-11-29 17:34:32
I am working on CakePHP 3 project which is a little big. I want to keep my application as much clean as possible by separating all media files from core application and that's why I have to store all media files on a separate subdomain as media.myproject.com and the project is accessible from www.myproject.com . Also in media.myproject.com there could be many directories as /root |- users |- avatar |- cover |- services |- logo |- banner |- slides |- clients |- logo |- avatar |- etc |- etc |- etc |- etc Now, to be able to access files in application view I want to set global variables that I

CakePHP 3.x - Load CSS in head tag for a specific action

♀尐吖头ヾ 提交于 2019-11-29 16:25:17
So far I can only load a specific CSS file for a specific action by include that CSS file within <body> tag from the corresponding view file. But I want to include that CSS file within <head> tag when a specific action is called? In your template, this can be achieved by linking to the css file using the block option : Creates a link(s) to a CSS style-sheet. If the block option is set to true, the link tags are added to the css block which you can print inside the head tag of the document. I.e. anywhere in the relevant template: $this->Html->css('special', ['block' => true]); This is output by

Why does formatting a date return the wrong year?

若如初见. 提交于 2019-11-29 15:54:49
I want to print formatted dates on my page. I have an object date and I use $this->Time->format() for formatting. Everything works fine before December 27th. Unfortunately all dates after the December 26th, formatting change my year number. This is my debug($date) object(Cake\I18n\Time) { 'time' => '2015-12-30T00:00:00+0000', 'timezone' => 'UTC', 'fixedNowTime' => false } This is my debug($this->Time->format($date, 'YYYY')) '2016' I tried to use i18nFormat but I have the same problem. Here is my debug($date->i18nFormat('YYYY')); '2016' Thanks for your help i18n dates are formatted using