cakephp-3.0

CackePHP 3 formatResults() ORDER by field created dynamically

梦想的初衷 提交于 2019-12-02 10:03:24
I wish to sort on a field that I dynamically creates in formatResults() $users = $this->Users ->find('all') ->formatResults(function ($users) use ($lat, $lng) { return $users->map(function ($user) use ($lat, $lng) { $user->distance = getDist($lat, $lng); return $user; }); }) ->order([ 'distance' => 'ASC' ]); [...] $this->set('users', $this->paginate($users)); The field $user->distance is not in the database. $user->distance contains a float ( getDist($lat, $lng); ) that is variable depending on the position of the user at the time of his request. ->order([ 'distance' => 'ASC' ]); return an

Error when retrieving associated data on. Linux only

那年仲夏 提交于 2019-12-02 09:46:33
Prior this problem I had another issue related to the same subject. The problem has been sorted thanks ta @ndm. Link the previous problem: Cakephp 3. Windows and Linux OS returning different result when querying the database I have an article page and I am retrieving the associated data with articles. Article comments. I have the following line of code $this->Articles->find()->contain('ArticleComments'); This line of code on both local Windows 10 machine and production Debian server retrieves all articles including their comment. find a link to a screenshot of the returned result using Cakephp

What “type” do I specify in addCase to return a column?

扶醉桌前 提交于 2019-12-02 08:32:02
问题 I'm trying to get a query working using a case statement, and can't figure out how to get the case to return a column value instead of a constant. I have the query working perfectly, except that the column names I'm providing for the results are being quoted or otherwise mishandled by Cake or maybe PDO somewhere down in a layer that I can't dig my way through. I got as far down as bindValue, but none of the documentation I encountered along the way tells me how to do this. I have found this

Using CakePHP 3.0 plugin

只愿长相守 提交于 2019-12-02 07:49:21
I'm currently building a new CakePHP app with version 3.0.0-RC1, and trying to install and use the jasig/phpCAS plugin. Using this guide, I've run the following command from the command prompt: composer require jasig/phpcas This correctly copies the jasig/phpcas files into the vendor directory of my app, but one of the other files that the guide says should be updated (vendor/cakephp-plugins.php) doesn't even exist. I've had a tough time accessing the plugin. I want to be able to call its static methods, and I keep getting errors of the form: Error: Class 'App\Controller\phpCAS' not found .

Redirect to referrer not working after Login

孤人 提交于 2019-12-02 07:31:20
After logging a user in, I want to redirect them back to where they came from but It's not working properly in CakePHP 3.5. Here are the required info's to help me figure out this problem. URL while login(session time out), http://dev.scys.com/db/admin?redirect=%2Fadmin%2Fstatuses This is my Auth config, $this->loadComponent('Auth', [ 'loginAction' => ['controller' => 'Admins', 'action' => 'login'], 'loginRedirect' => ['controller' => 'Admins', 'action' => 'index'], 'logoutRedirect' => ['controller' => 'Admins', 'action' => 'login'], 'unauthorizedRedirect' => $this->referer(), 'authenticate' =

Dynamically change database connection in cakephp 3

只愿长相守 提交于 2019-12-02 07:22:37
I'm trying to change the database connection used in cakephp 3 on the fly. Every answer to this question that I found refers to cakephp 2 ( These three for instance). This guy found a solution for cakephp 3 having a finite number of databases, and specifically defining which Database would be used by which Table file. The thing is that I want to create a new database for every new user, and change to his database when he logs in. I can't know in advance all the databases that will exist, to write it in the config/app.php file. And I can't set the default database in each /src/Model/Table file,

Cakephp 3 Callback method not reached

瘦欲@ 提交于 2019-12-02 07:19:07
I have a problem with the afterDelete callback method. I can't use them. Inside one of my "Storages" plugin controllers I want to delete a record and after that I want to do some other thinks, but the callback method is not reached. I have checked this with adding a log message inside the afterDelete() callback method. This is the controller where I removed a record: namespace Storages\Controller; class StoragecontainerBlocksController extends AppController { public function initialize() { parent::initialize(); $this->loadComponent('RequestHandler'); } public function ajaxDeleteBlockElement()

CakePHP 3.0 cannot get 2 items from 1 table

旧时模样 提交于 2019-12-02 07:06:59
In a football match i have 2 clubs "Home-Club" and "Away-Club" . I have created table "match" and "club" in MySQL. In "match" table has 2 foreign key "home_id" and "away_id". I'm using cakePHP to show list matches, match information contain names of "Home-Club" and "Away-Club". How to get name of "Home-Club" and "Away-Club" in template file ( .ctp file ). For now I using this code in the template file: $match->club->name Code in Controller: public function index() { $this->paginate = [ 'contain' => ['Club'] ]; $this->set('match', $this->paginate($this->Match)); $this->set('_serialize', ['match

cakephp Model validation error message not displaying in hasOne association

做~自己de王妃 提交于 2019-12-02 05:17:25
问题 i want to do model validation with association in a single form. i have two tables users (parent table) and user_details (child table).now model validation is working for users table only.i want it for userDetails table also. relation between them is hasOne . validation working for only users table because i have created newEntity for users table only. usersController.php (controller code) public function add() { $user = $this->Users->newEntity(); $userDetail = $this->UserDetails->newEntity()

Select all except one field in cakephp 3 query

为君一笑 提交于 2019-12-02 04:33:11
I just want to select all fields except one field in cakephp 3. Ex. $this->select('fname', 'lname', 'mname', 'email', 'password', 'status', 'created', 'modified'); Here i want to select all fields except created and modified because my other table have apprx 30 fields and i want to select 28 fields and don't want to mentioned each and every field in select function because it is time consuming. Can you please suggest a better way. As of CakePHP 3.6 the selectAllExcept() method has been introduced, which will select all columns from the schema that belongs to the given table, except those