cakephp-3.0

CakePHP 3 implementedEvents() does not fire in emailer

痴心易碎 提交于 2020-01-05 04:04:28
问题 According to documentation , I should be able to add implementedEvents directly to my mailer to seperate all my mailing logic from my codes. However, when I follow the exact examples in documentation; I see my implemented event function does not work. (not sending emails & does not log anything) Should I implement my emailer class to somewhere? If so, how should I register my emailer class? This is my mailer class: <?php namespace App\Mailer; use Cake\Mailer\Mailer; use Cake\Log\Log; /** *

CakePHP 3. Validation of uploaded file extension

前提是你 提交于 2020-01-04 05:52:06
问题 I am using CakePHP 3. I have the upload field and want to permit uploading only .pdf and .doc(x) files. How can I add that properties to the following validator? $validator ->notEmpty('article'); 回答1: Simply add the extension rule in your validation which is define in http://api.cakephp.org/3.0/class-Cake.Validation.Validation.html extension( string|array $check , array $extensions ['gif', 'jpeg', 'png', 'jpg'] ) example: $validator ->allowEmpty('profile_image') ->add('profile_image', [

Why am I getting “TableRegistry not found” in CakePhP 3.0?

核能气质少年 提交于 2020-01-03 17:01:24
问题 I have a class full of static functions that I call UtilityFunctions in my Model/ directory. But that class cannot access TableRegistry::Get even though the "use" statements are in place. Below is the code and the error. namespace App\Model\Table; use Cake\ORM\TableRegistry; use App\Model\Entity\Device; class UtilityFunctions { public static function getDevice($deviceInfo) { $devicesTable = TableRegistry::get('Devices'); // TableRegistry not found $query = $devicesTable->findByDeviceInfo(

List all tables in cakePHP 3.x

最后都变了- 提交于 2020-01-03 15:37:17
问题 I have been trying to work this one out. In cakePHP 2 I could use: $tables = ConnectionManager::getDataSource('default')->listSources(); But in CakePHP 3.x I can't work out what to use? I have looked at the link cakephp get schema for list of tables Unfortunately it doesnt help with cakePHP 3.0? 回答1: We can get list of table in cakephp3 using very similar pattern as $tables = ConnectionManager::get('default')->schemaCollection()->listTables(); 回答2: I just had the same problem. Try using the

how to configure routes for child controllers in CakePHP 3.x?

别等时光非礼了梦想. 提交于 2020-01-03 03:08:07
问题 Reports has many ReportInstances ReportInstances belongs to Reports I would like to have the url /reports/:report-id/instances to point to the action index_by_report_id inside ReportInstancesController.php How do I configure the routes.php accordingly? UPDATE: I tried nested resources as described here: http://book.cakephp.org/3.0/en/development/routing.html#creating-nested-resource-routes Here are my routes $routes->resources('Reports', [ 'map' => [ 'standard' => [ 'action' => 'standard',

cakephp 3.x cascade delete not working

时光毁灭记忆、已成空白 提交于 2020-01-02 07:58:08
问题 I have 3 tables names articles,comments,addresses. articles -> fields(id,title,body) comments -> fields(id,article_id,comment) addresses-> fields(id,article_id,address) and in my articles controller i have kept dependent=>true and also cascadeCallbacks=>true. First i tried with dependent => true,i dint work then added cascade, still it does not work. Below is my code. $this->hasMany('Comments', [ 'className' => 'Comments', 'dependent' => true, 'cascadeCallbacks' => true, ]); $this->hasOne(

Cakephp 3 Callback method not reached

心不动则不痛 提交于 2019-12-31 04:00:11
问题 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() {

how to add ` character to sql queries in cakephp 3

匆匆过客 提交于 2019-12-31 04:00:10
问题 I have a table with special fields name such as 'from' and 'order' (this table used with another cms and I can't change table structor) I want add a record using cakephp 3 ,but I got 'Database Error'. it seems queries of cakephp 3 is not sanintized with ` character! my code in controler: $tour = $this->Tours->patchEntity($tour, $this->request->data); $this->Tours->save($tour); generated SQL is: INSERT INTO tour_tours (title, from , to, description, duration) VALUES ('tour title', 'from', 'to'

How to use multiple Auth components?

时光怂恿深爱的人放手 提交于 2019-12-31 02:50:28
问题 I configure a Auth component to "Admin page", using the users model. But now, I also want create/configure a Auth to the clients. I try "rewrite" the inialize() //This is in my ClientsController.php public function initialize() { $this->loadComponent('RequestHandler'); $this->loadComponent('Flash'); $this->loadComponent('Auth', [ 'authenticate' => [ 'Form' => [ 'userModel' => 'clients', 'fields' => ['username' => 'client_email', 'password' => 'client_password'] ] ], 'loginRedirect' => [

CakePHP 3.0.8 translate behavior and data validation (requirePresence, notEmpty)

梦想的初衷 提交于 2019-12-30 11:32:34
问题 My problem is simple, yet I can't figure out how to solve it. My website is multilanguage. I want the user to be able to add an article in multiple language if he wants, while requiring the inputs of his language (depending on his locale). Problem is, with CakePHP's conventions about translation, all the inputs must end with the field's name, no matter what language. So all the fields has the same rule for the same field. I can't make one "name" required while another in another language not