cakephp-3.0

CakePHP 3.x how do I include the params in the mapped resources?

感情迁移 提交于 2019-12-13 04:38:21
问题 this is what I have in my routes: Router::scope('/', function ($routes) { $routes->extensions(['json']); $routes->resources('CustomerCompanies', [ 'map' => [ 'get_by_account' => [ 'action' => 'get_by_account', 'method' => 'GET', ] ] ]); This is my method get_by_account inside CustomerCompaniesController.php : /** * Pagination method by Customer Account id * * @param string|null $id Customer Account id. * @return void Redirects to index. * @throws \Cake\Network\Exception\NotFoundException When

CakePHP 3.x search form with 11 different models

时间秒杀一切 提交于 2019-12-13 03:54:37
问题 I have an application in CakePHP 3.5.13. The application is connected to a legacy database - that is to say it has not been written according to Cake's naming conventions. I have baked the application which has generated some Table and Entity classes. Part of the application allows the user to perform a search. I'm wanting to use the Form Helper but am unsure how to name/configure things: The template file where the search form lives has 11 text inputs. Each of these relates to data stored in

cakephp 3 add default class to inputs

强颜欢笑 提交于 2019-12-13 03:14:27
问题 i'm trying to add a default class for each input in my cakephp 3 app. Example of what i want: Input: <echo $this->Form->control('email'); Output: <input class="form-control" class="is-invalid"/> Desired output: <input class="form-control is-invalid"/> for this i have edited input template of FormHelper $this->viewBuilder()->setHelpers([ 'Form' => [ 'templates' => [ 'input' => '<input class="form-control" type="{{type}}" name="{{name}}"{{attrs}}/>' ] ] ]); the problem is that {{attrs}}

How to Hide Fields in Associated Data CakePhp 3.x

橙三吉。 提交于 2019-12-13 03:06:38
问题 I have the following tables, basically two Tables in join. How can I remove the _joinData fields when I make a find of associated records of Pops? // PopsTable.php public function initialize(array $config) { parent::initialize($config); $this->setTable('pops'); $this->setDisplayField('name'); $this->setPrimaryKey('id'); $this->belongsToMany('Menus', [ 'targetForeignKey' => 'menu_id', 'foreignKey' => 'pop_id', 'joinTable' => 'pop_menus', ]); } // MenusTable.php public function initialize(array

Use OR conditions on associated model in CakePHP 3

别来无恙 提交于 2019-12-13 01:53:49
问题 I have 3 models, the base model is Jobs and Customers, Contacts are the models associated with jobs. Here is the association. $this->belongsTo('Customers', [ 'className' => 'Customers', 'foreignKey' => 'customer_id', 'joinType' => 'INNER' ]); $this->belongsTo('Contacts', [ 'className' => 'Contacts', 'foreignKey' => 'contact_id', 'joinType' => 'INNER' ]); I want to search a text in all the 3 tables and return the job records which are having the search text at least any one of the tables... I

Flash Message in cakephp 3 it doesn't working

最后都变了- 提交于 2019-12-13 01:25:57
问题 I'm new with cake sorry if this is a simple problem. When i finish to save the data and i try to show a message with information about if the user is saved or could not saved , show me the next error : Error: Call to a member function error() on a non-object File C:\wamp\www\proyecto\src\Controller\AdministradorsController.php Line: 76 AdministradorsController extends AppController public function add() { $administrador = $this->Administradors->newEntity(); if ($this->request->is('post')) {

CakePHP3 custom finder method using contain and does not work when attempt to display the associated model field

。_饼干妹妹 提交于 2019-12-12 23:33:06
问题 This is my custom finder method inside DynamicViewsTable.php public function findAccessibleByUser(Query $query, array $options) { if (empty($options['User']['id'])) { throw new Exception("Current User not set", 1); } $query->select(['DynamicViews.id', 'DynamicViews.title', 'UsersAccessDynamicViews.ordinal_ranking']) ->contain(['UsersAccessDynamicViews']) ->where([ 'UsersAccessDynamicViews.user_id' => $options['User']['id'], ]) ->order(['UsersAccessDynamicViews.ordinal_ranking' => 'ASC']);

CakePHP3.x controller name in url when using prefix routing

*爱你&永不变心* 提交于 2019-12-12 19:47:18
问题 I am trying to use prefix routing in CakePHP3. I added the following lines to /config/routes.php. Router::prefix("admin", function($routes) {     // All routes here will be prefixed with ‘/admin‘     // And have the prefix => admin route element added.     $routes->connect("/",["controller"=>"Tops","action"=>"index"]);     $routes->connect("/:controller", ["action" => "index"]);     $routes->connect("/:controller/:action/*"); }); After that, I created /src/Controller/Admin/QuestionsController

How to print associated data in the index view

点点圈 提交于 2019-12-12 19:16:05
问题 $subjects = $this->Subjects ->find('all', [ 'contain'=> [ 'Users' ], 'fields'=> [ 'Users.username', 'Users.email' ] ]) ->hydrate(false) ->toArray(); $this->set('subjects', $subjects); how can i loop the data in the INDEX view of Subjects controller to display like this image 回答1: Sample Result from your vardump : <?php $array = array( 0 => array( 'math'=>40, 'english'=>40, 'history'=>40, 'science'=>40, 'user_id'=>64 'user'=> array( 'id' => 6 'name' => 'User', 'email' => 'user1@sample.com' ) )

CakePHP 3 “Login As” wtih Multiple Auth Sessions

烈酒焚心 提交于 2019-12-12 16:42:42
问题 Using prefixes, I have separate sessions and logins for admins versus users. For example the AppController.php has: if ($this->request->prefix == 'admin') { $this->loadComponent('Auth', [ 'authenticate' => [ 'Form' => [ 'userModel' => 'Admins', 'fields' => ['username' => 'email', 'password' => 'password'] ], ], 'loginAction' => [ 'controller' => 'Admins', 'action' => 'login' ], 'loginRedirect' => [ 'controller' => 'Admins', 'action' => 'index' ], 'logoutRedirect' => [ 'controller' => 'Admins'