cakephp-3.0

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

妖精的绣舞 提交于 2019-11-29 15:41:19
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' ]); } ]; $this->paginate['fields'] = [ 'EventTicketSales.id', 'EventTicketSales.event_id',

How to create cookies at controller level in CakePHP 3.5?

╄→гoц情女王★ 提交于 2019-11-29 15:10:36
I have problems to get cookies to work in cakephp 3.5.x. in earlier versions I've used the Cookie component but this is now deprecated. Its unclear for me how to use this new middlewarestuff for reading and writing cookies. The documentation is unclear for me. It shows me how to set up the cookie middleware but not how to handle creating cookies in a controller. Is there anyone who has handled cookies in 3.5.x? The middleware only replaces the encryption part of the Cookie component (which basically is the only thing it did as of CakePHP 3.0 anyways), if required it automatically encrypts and

Cakephp3 : using another model in a controller

和自甴很熟 提交于 2019-11-29 13:08:36
I started an app with CakePHP3 and i need to record some users's actions. So, I have migrated my log structure, I have baked my controller & model and now, I try to get a log when a user log in. I updated my UsersController like this: namespace App\Controller; use App\Controller\AppController; use App\Model\Table\LogsTable; use App\Model\Entity\User; use App\Model\Entity\Log; class UsersController extends AppController { public function login(){ $this->viewBuilder()->layout('external'); $user = $this->Users->newEntity(); if($this->request->is('post')){ $user = $this->Auth->identify(); if($user

CakePHP 3.x - hasMany through association - find

↘锁芯ラ 提交于 2019-11-29 10:24:48
问题 Assuming I have exactly the setup as in CookBook here: http://book.cakephp.org/3.0/en/orm/associations.html class StudentsTable extends Table { public function initialize(array $config) { $this->belongsToMany('Courses', [ 'through' => 'CourseMemberships', ]); } } class CoursesTable extends Table { public function initialize(array $config) { $this->belongsToMany('Students', [ 'through' => 'CourseMemberships', ]); } } class CoursesMembershipsTable extends Table { public function initialize

How to load non-default models?

独自空忆成欢 提交于 2019-11-29 09:56:33
In CakePHP2.x, I have frequently used $uses attribute in controllers but it seems that this attribute is no longer available in CakePHP 3.0. The only way I know to load models which is not default one is to use loadModel() method. Is this recommended way to load models? Or is there any other way to load models? Your observations are correct, there is no $uses property anymore, instead models/tables that do not match the controller (ex PostsTable for PostsController ) and are not available via associations, must be loaded explicitly. This can be done by using either Controller::loadModel()

List all controllers/actions in Cakephp 3

随声附和 提交于 2019-11-29 08:35:00
问题 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. 回答1: 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

CakePHP 3: Missing route error for route that exists

…衆ロ難τιáo~ 提交于 2019-11-29 03:58:11
CakePHP 3.0 I'm getting a "Missing Route" error for a route that exists. Here are my routes: #my admin routes... Router::prefix('admin', function($routes) { $routes->connect('/', ['controller'=>'Screens', 'action'=>'index']); $routes->connect('/screens', ['controller'=>'Screens', 'action'=>'index']); $routes->connect('/screens/index', ['controller'=>'Screens', 'action'=>'index']); //$routes->fallbacks('InflectedRoute'); }); Router::scope('/', function ($routes) { $routes->connect('/login', ['controller' => 'Pages', 'action' => 'display', 'login']); $routes->connect('/pages/*', ['controller' =>

Conditions to paginate for belongsToMany CakePHP 3

妖精的绣舞 提交于 2019-11-29 02:28:22
I have the tables Semesters, Disciplines and a jointTable Semesters_Disciplines. I want to create a action index in DisciplinesController with a semester_id as parameter, which list with paginate just the disciplines what belongs to the semester with the id passed in the parameter. I tried this: public function index($semester_id) { $options = ['semester_id' => $semester_id]; $this->paginate = ['conditions' => $options]; $this->set('disciplines', $this->paginate($this->Disciplines)); $this->set('_serialize', ['disciplines']); } You'll have to use a query that uses matching or joins to be able

Responsive bootstrap designing in CakePHP 3x

一曲冷凌霜 提交于 2019-11-29 01:49:54
As CakePHP 3x has inbuilt responsive feature, I would like to know the element structures and class definitions. I'm indeed familiar with Twitter Bootstrapping ( done in cake 2x projects). But need to familiarize with CakePHP 3x version, as its new in framework! I looked into css/base.css and found few classes for elements, like Grids: .small-1(to 12), .medium-1(to 12), .large-1(to 12) Offsets: .small-offset-1(to 12), .medium-offset-1(to 12), .large-offset-1(to 12) Align: .left, .right.... etc As responsive sites run with standard element structures, is there any reference for the Cake's

Check if record exists in CakePHP3

核能气质少年 提交于 2019-11-28 20:24:12
In CakePHP 2 I always used empty to check if there any result. <?php $result = $this->Modelname->find('first', ['conditions' => ['field' => 'value'] ] ); if ( empty($result) ) { // Bad Request } In CakePHP 3 it looks weird to me. $fancyTable = TableRegistry::get('FancyTable'); $query = $fancyTable->find()->where(['name' => 'fancy', 'active' => 0]); if ( 0 === $query->count() ) { // Bad Request } Is this the right way? You can do: $fancyTable = TableRegistry::get('FancyTable'); $exists = $fancyTable->exists(['name' => 'fancy', 'active' => false]); Krunal Dave Use something like this: if ($query