cakephp-3.0,phpcas , Using CakePHP 3.0 plugin

Using CakePHP 3.0 plugin


Tag: cakephp-3.0,phpcas

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. (The exact directory in the error changes depending on where I'm calling the method from.)

I don't know if this is due to not having the cakephp-plugins.php file, or if I'm not calling the plugin correctly. It's my understanding that if the plugin is loaded I should just be able to call static methods on it like this: phpCAS::methodName()


First of all jasig/phpcas is not a CakePHP plugin. And the vendor/cakephp-plugins.php file is created by the CakePHP plugin installer, so if you don't see such a file, you seem to have either not installed any plugins yet, or you are not using a recent version of the installer, as the creation of this file has been introduced just recently.

Regarding the error about the class not being found, you are missing the leading namespace separator (\phpCAS::methodName()) to access the class in the global namespace, respectively you are missing a proper import (use phpCAS;) that would make the class available in the current namespace.

In case you are not familiar with namespaces, you may want to start with:


make SQL function SUBSTRING_INDEX work in cakePHP query builder

I have a fullname column for authors and would like to extract the surname into another column. I do that with the following raw SQL: SELECT name, SUBSTRING_INDEX(`name`, ' ', -1) AS `surname` FROM qr.authors; Output: Under "Using SQL Functions" the Cookbook says: In addition to the above functions, the...

Disable password hashing for particular users

We are using a single table for both admin and normal users. We need to save the admin password in hash format, but save the user password in plain text. How do do that with CakePHP 3.0 EDITED: User's username and password are used as a login credentials on another...

Cakephp 3.x Ajax deleting data gives this Error: Unknown method “isNew”

I try to delete a record with Ajax in CakePhp 3.0.6. Here is the jquery in my View (start.ctp) <script> $('.delavailable').click(function(){ var dataString = 'ID=' + $(this).attr('id'); $.ajax({ type: 'POST', url: '/ID/admins/delavailable.json', data: dataString, beforeSend: function(xhr) { xhr.setRequestHeader('Content-type', 'application/x-www-form-urlencoded'); } }); }); Controller (AdminsController.php) public function delavailable() { $this->loadModel('TeamFree'); if($this->request->is('ajax'))...

manually convert input parameters in type instance

I have some problem to save date value in varchar field. I'm trying to convert an input date (like 17/06/2015) to an Time instance and then store it in my database as 2015-06-17 here an exemple of the entity which i want to save (int) 1 => object(App\Model\Entity\Valeur) { 'new'...

Testing beforeFilter() function

I am doing unit testing for a PHP application using CakePHP framework. The function that I am testing is beforeFilter() which basically loads the models. public function beforeFilter(Event $event) { parent::beforeFilter($event); $this->loadModel('Model1'); $this->loadModel('Model2'); $this->loadModel('Model3'); $this->loadModel('Model3'); } How should I test this function ? What assertions I need to make in...

Cakephp3 redirect in beforeFilter is not working

When I add the $this->redirect statement inside a beforeFilter of a controller and return afterwards, the redirection is being ignored. When I move the redirect statement inside an action of the controller, it works fine. Does someone has an idea what I am doing wrong? public function beforeFilter(Event $event) {...

Cakephp3 transaction find query

When making a transaction in cakephp3 and adding a get() query inside all works fine. But why is a find() query not performed inside the transaction? I have the following controller in cakephp3: <?php namespace App\Controller; use Cake\Core\Configure; use Cake\Network\Exception\NotFoundException; use Cake\View\Exception\MissingTemplateException; use Cake\Network\Session; use Cake\Event\Event; use Cake\Network\Http\Client; use Cake\ORM\TableRegistry;...

cakephp use record values in afterDelete

I am using the soft delete plugin for my EmployeesTable.php in CakePHP 3.0. When I soft delete an employee I wish to update their associated user table with $user->set('active', false); within the afterDelete() My problem is getting the user_id used in the employees table into the afterDelete() I have even...

How to increase cakephp Auth component session expire time

I am using Auth component to check user is logged in. Here is my AppController's initialize function public function initialize() { parent::initialize(); $this->loadComponent('Flash'); $this->loadComponent('Auth', [ 'authenticate' => [ 'Form' => [ 'fields' => [ 'username' => 'username', 'password' => 'password' ], 'passwordHasher' => [ 'className' => 'Md5',//My own password hasher...

Cakephp 3.0 sesson time expire re-direct to home page

How to re-direct home page when the session id time is expire, not using auth id i have set the another value is session in Cakephp 3.0

CackePHP 3 formatResults() ORDER by field created dynamically

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...

Different cakephp datasource for local and live

My MySQL connection details are different for both my local connection and my deployed live hosted. I am using CakePHP 3 At the moment I have to keep changing the default datasource which is not really the best way to do it. I have not added two datasources but I...

CakePHP 3: change order in dateWidget

I found on the CakePHP developer's guide the following hint on how to adjust the order of the fields when using the date form input. It says To control the order of inputs, and any elements/content between the inputs you can override the dateWidget template. However, I cannot find anywhere...

How can I add FOR UPDATE to a cakephp3 query?

Is there a way to add FOR UPDATE to a find (SELECT) query in cakephp3? I found this hack: but it does not work since the limit value must contain only of a number. Another discussion on a similar topic can be found under

Radio Button CakePHP 3.0

In CakePHP 2.0 I can actually add 'before', 'after' and 'separator' attributes to the radio button. The attributes will create a div element between my radio options. It seems like these options have been removed from CakePHP 3.0. How can I do that in CakePHP 3.0? <div class="col-xs-6 col-sm-6 col-md-6...

cakephp 3 order by query generates 14 queries with associate tables instead of 1

My cakephp3 app works very well and now I wish to order some of the queries by the associated table fields. The query works fine when ordered by a field in the current model. But if I choose to order by a field Models.field in an associated table I now...

How to create a join table record

So I'm trying to add a record to my join table, but it doesn't seem to work, no errors are given either. So here's my data array (which saves correctly without a problem) array(3) { ["id"]=> string(2) "32" ["title"]=> string(5) "Hello" ["participant"]=> array(1) { [0]=> array(1) { ["id"]=> int(1) }...

Cakephp 3 - MissingDatasourceConfigException when running phpunit test

I am trying to run some unit tests in CakePHP 3 with PHPUnit 4.7.3, but I`m getting the following error: PHPUnit 4.7.3 by Sebastian Bergmann and contributors. There was 1 error: 1) App\Test\TestCase\Model\Table\MoviesTableTest::testFindMoviesByGenre Cake\Datasource\Exception\MissingDatasourceConfigException: The datasource configuration "default" was not found. C:\xampp\htdocs\movie-pal\vendor\cakephp\cakephp\src\Datasource\ConnectionManager.php:188 C:\xampp\htdocs\movie-pal\vendor\cakephp\cakephp\src\ORM\TableRegistry.php:191...

how can I return the validation errors for a REST call?

I am making a REST api for my application. It almost works, but I want it to return the validation errors when they occurs. With CakePHP 2.x I see there was an invalidFields method, but it's not there anymore with Cake3. I see, instead, that there is an errors method...

Best rules to get data with Contain

In CakePHP 3 ORM has changed and I can't find the proper way to select needed data from the database. In CakePHP 2, I use contain('',''), but In CakePHP 3 this code doesn't work. So how can I select only id and name from User? The code: $query = $data->find()->contain(['Users'])->execute()->fetchAll('assoc');...

How to Edit User CakePHP 3

So I've been trying to get an edit user functionality working in my app, and I'm a little confused as to how to go about doing this with CakePHP 3. This is what I've got for my edit action in my UsersController.php: public function edit() { $this->layout = 'dashboard'; $user...

Remove INTL extension support in cakephp

I am using CakePHP 3.0 framework. Is there any way to use CakePHP framework without the intl extension support?

how to cakephp2 project transplanted to cakephp3?

I want to cakephp2 project transplanted to cakephp3 problem. I must retain the user's information. How to make them have the same way to generate password? Here's how I generate passwords by cakephp2. App::uses('AuthComponent', 'Controller/Component'); .... public function beforeSave($options = array()) { $this->data['User']['password'] = AuthComponent::password( $this->data['User']['password'] ); return true; }...

Translating query involving join table from CakePHP 1.3 to 3

I'm migrating an application from Cake 1.3 to 3.0. My database has teams and people (with teams_people to connect them via belongsToMany relations) and divisions (teams belongTo divisions). The teams_people table has additional information, like whether the person's role on the team (captain, player), jersey number, position, that sort of...

Get last inserted ID after inserting to associated table

Employees table has a field named current_address_id. I'm adding a new address to Addresses like: $updatedEntity = $this->patchEntity($employee, [ //some other fields 'user' => $userData, 'employees_phones' => $phonesData, 'employees_addresses' => $addressesData, ], [ 'associated' => ['Users', 'EmployeesPhones', 'EmployeesAddresses'] ]); $this->save($updatedEntity); I'm inserting the new address successfully but now I need...

How do I disable CakePHP's client side email validation?

The kind of validation that pops out even before sending the data to the server. The other fields in my form, namely 'name', 'message', had these too but I removed that by taking their respective validators in my FormTable. Did the same for the email validator but its still there....

How to change the message in buildRules [CakePHP 3]?

The function below is for being sure the e-mail from form is unique, if it's already in use a message is showed. I want to change this message. public function buildRules(RulesChecker $rules) { $rules->add($rules->isUnique(['username'])); $rules->add($rules->isUnique(['email'])); return $rules; } I tried this way: public function buildRules(RulesChecker $rules) { $rules->add($rules->isUnique(['username'])); $rules->add($rules->isUnique(['email']), ['errorField'...

Change the Default Fav icon in cakephp 3.0

How to change the title logo in cakephp 3.0 ? Added another image instead of default cakephp logo image Anyone explain with example Thank you...

Removing the debugging bar from cakephp

I am creating a new project in cakephp, I completly customized the view page, but since I am new to cakephp framework unable to understand how to remove the debugging bar given bottom of the page. I checked and tried every possible things, but not getting. Any suggestion will be...

Cakephp 3 and Postgre add.cpt doesnt work id_parent

I'm trying to create an easy page on cakephp 3 using postgreSQL. I do not understand where is the problem: I create a table "menus". When I add a new instance (add.cpt) the parent field is empty so I cant add a parent. It's all generated from command "cake bake...

How to choose the fields from a associated model at find

Before I had this: //ArticlesController::index $articles = $this->Articles->find('all', [ 'contain' => ['Comments'] ]); So I set the fields key: //ArticlesController::index $articles = $this->Articles->find('all', [ 'fields' => ['title', 'text], 'contain' => ['Comments'] ]); Since I set the fields key the result of the find is not bringing the comments anymore....

CakePHP 3 Multiple BelongsTo Associations

I am using cakePHP version 3.x. When i query the MessagesTable i want to get the Users data for the the sender and the receiver of the message. I have done this many times in cakePHP 2 but i cant figure out why it isn't working in version 3.x. i...

How to self join a many to many table in cakephp 3?

I try to self join my table user to get parent-child associations but it didn't work here is my association in the Users model: $this->belongsToMany('Parents', [ 'className' => 'Users', 'joinTable' => 'users_users', 'foreignKey' => 'id', 'targetForeignKey' => 'parent_id' ]); $this->belongsToMany('Childs', [ 'className' => 'Users', 'joinTable' => 'users_users', 'foreignKey' => 'id',...

core difference between set and serialized in cakephp 3.0?

$player = $this->Players->get($id, [ 'contain' => [] ]); $this->set('player', $player); $this->set('_serialize', ['player']); if i will remove $this->set('_serialize', ['player']) than i am not getting any difference at my view. <h6 class="subheader"><?= __('First Name') ?></h6> <p><?= h($player->first_name) ?></p> <h6 class="subheader"><?= __('Last Name') ?></h6> <p><?= h($player->last_name) ?></p> <h6 class="subheader"><?= __('Email')...

CakePHP 3.x: hide shell class

I have a src/Shell/AppShell.php class that is extended to all other shell classes and which contains common methods used by all other classes. In other words, this class doesn't contain any method callable directly. If I launch the console: bin/cake the class is automatically detected and is shown: $ bin/cake...

Cakephp: How to use migration to insert records

I'm using CakePHP v3.x and I'm trying to figure out how to insert some records via the migrations tool. The documentation only lists methods for modifying the schema. Will I need to insert records manually with raw SQL?

Using slug in CakePHP v3

I plan to upgrade my CakePHP v2 to v3 website. So I start to learn by looking at the Blog tutorial & it work fine. Next, I start to customize base on my CakePHP v2 site. The first thing I would like to do is using slug in URL instead...

Customize login cakephp3

I have a form like this: email [input] password [input] Login-Button I want to eliminate the "email" and "password" text and put them inside the inputs like placeholder and also change the "login" text to "LOGIN". This is my login ctp. <fieldset style="background:#F44336"> <?= $this->Form->create() ?> <?= $this->Form->input('email') ?> <?=...

How to Save Associated Table in CakePHP 3.0

Hi I just made a function to save data in multiple tables. Even Though, I followed the instruction in Instruction for Cakephp 3.0 It saves data in only one table. Please see what i missed. Thank you public function saveTest() { $goods = TableRegistry::get('Goods'); //$data = $this->request->data; $data = [...

How to handle Imagine exception in CakePHP 3

I suppose I don't manage correctly the exception using Imagine libray. My code is: use .... use Imagine\Exception; .... try { $imagine = new Imagine(); $image = $imagine->open($img_path . DS . "tmpfile." . $extension) ->resize(new Box($cwidth, $cheight)) ->crop(new Point($offsetx, $offsety), new Box(500, 500)); ... } catch (Imagine\Exception\Exception $e) { die("catch...

join and orwhere ends to AND

I have the follwing code: $_duplicates = $this->find() ->innerJoin( ['c' => 'contacts'], //alias [ 'Contacts.contactname != ' => '', ' <', ' > ' => 0 ] ) ->select(['', 'Contacts.contactname', 'Contacts.legalname', '', 'c.contactname', 'c.legalname']) ->orWhere([ 'LEVENSHTEIN(Contacts.contactname, c.contactname) <= ' => $distance, 'LEVENSHTEIN(Contacts.contactname, c.legalname) <= ' => $distance, 'LEVENSHTEIN(Contacts.legalname, c.contactname)...

Error loading association from controller in cakephp

I can't get this simple query right. I need to join my adresses table to my annonces table. I supose this should be farly strait forward but I simply can't get it to work. I firstly made my adresse table object like this class AdressesTable extends Table { public function...

Preventing malicious users update data at add action

Here is a basic add action: public function add() { $article = $this->Articles->newEntity(); if ($this->request->is('post')) { $article = $this->Articles->patchEntity($article, $this->request->data); if ($this->Articles->save($article)) { $this->Flash->success('Success.'); return $this->redirect(['action' => 'index']); } else { $this->Flash->error('Fail.'); } } $this->set(compact('article')); } If a malicious user injects at form a field with name id and set...

CakePHP 3.0: SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax

I faced saving data to database using Form in CakePHP 3.0. //add.ctp <div> <?= $this->Form->create($deposit) ?> <fieldset> <legend><?= __('Add') ?></legend> <?php echo $this->Form->input('date'); echo $this->Form->input('profile_id', ['options' => $profiles]); echo $this->Form->input('amnt'); echo $this->Form->input('desc'); echo $this->Form->input('user_id', ['options' => $users]); ?> </fieldset> <?= $this->Form->button(__('Submit'))...

cakephp 3 bootstrap-ui change prev/next text

I have FriendsofCake Bootstrap-ui plugin. I see in the source that it accepts text for the pagination prev and next labels. I am not sure how to exactly set the config option though. PaginatorHelper.php if (isset($options['next'])) { if ($options['next'] === true) { $options['next'] = $this->config(''); } $options['after'] = $this->next($options['next'], ['escape'...

Redirect to a homepage cakephp 3

I've followed the articles tutorial from cakephp 3 website and created the website Now there is add article, delete article and edit article actions. When I delete an article it redirect me to http://localhost:8888/test/articles/delete/14 Here is the delete code. public function delete($id) { $this->request->allowMethod(['post', 'delete']); $article = $this->Articles->get($id); if...

cakephp 3 and view cells with use of Cookie

I can't find any info about using $this->Cookie in view cells. When i wrote code like this, error will arise: namespace App\View\Cell; use Cake\View\Cell; class CityCell extends Cell { public function display() { $this->Cookie->config('encryption', false); $cookie = $this->Cookie->read('city'); } } and the error is: Error: Call to a member function...

CakePHP - Controller testing failed because of Security component

I am trying to test controller methods (add, edit, ...) that use Security component. ContactsController public function initialize() { $this->loadComponent('Security'); } public function add() { $contact = $this->Contacts->newEntity(); if ($this->request->is('post')) { $contact = $this->Contacts->patchEntity($contact, $this->request->data); if ($this->Contacts->save($contact)) { $this->Flash->success(__d('contact_manager', 'The contact has been saved.')); return $this->redirect(['action' =>...

cakephp 3 multi level associated save

I have a Users model which has a hasOne relationship to an Employees model. When I save a user I also add a record in the Employees table with the user_id. This works fine. The Employee can be associated to belongsToMany Courses through CoursesEmployees table. This saves ok when I...

CakePHP 3.0 IIS web.config

All of my urls for images and css or being rendered with app prepended /app/favicon.ico /app/img/logo.png /app/css/styles.css The content of the pages is rendering fine, just not the images and css. My web.config looks like this, but doesn't seem to be helping these urls. Thus they are all resulting in...