cakephp-3.0

CakePHP 3 - Configure route to allow optional parameter

风格不统一 提交于 2019-12-12 16:30:58
问题 I have a route like this: $routes->connect('/custom/url', [ 'prefix' => 'admin', 'controller' => 'Things', 'action' => 'index' ]); I want to allow an optional passed parameter so the URL can be /custom/url/123 but also still allow it to not have the parameter at all, like /custom/url . If I change the route to /custom/url/:param it throws an exception if I visit the URL without the extra parameter. How can I make the parameter matching lazy? 回答1: routes like: $routes->connect('/custom/url/*',

How to get CakePdf to work in CakePHP 3.x?

给你一囗甜甜゛ 提交于 2019-12-12 15:09:49
问题 I have installed CakePdf plugin in app/plugins folder and followed all the documentation possbile, thus my settings are as following: // config/bootstrap.php Plugin::load('CakePdf', ['bootstrap' => true, 'routes' => true]); Configure::write('CakePdf', [ 'engine' => 'CakePdf.WkHtmlToPdf', 'binary' => '/wkhtmltopdf/bin/wkhtmltopdf', 'margin' => [ 'bottom' => 15, 'left' => 50, 'right' => 30, 'top' => 45 ], 'orientation' => 'landscape', 'download' => true ]); // config/routes.php Router:

Rewriting cakephp path in cakephp 3.0

吃可爱长大的小学妹 提交于 2019-12-12 11:35:58
问题 I have a need to remove the app folder from the URL. Example URL is: mydomain.com/cake_app/vechicles/add What I need to have instead is mydomain.com/vechicles/add NOTE! In the root of mydomain.com I have a WordPress installation running, so I only need to route users to cake application if there is a vechicles controller name in the URL. I have found many examples for how to do it via .htaccess files, but these were for CakePHP <3.0 and seem not to work with the current version. 回答1: Add

cakephp3 how to check if entity is a newly inserted in afterSave callback?

瘦欲@ 提交于 2019-12-12 10:38:38
问题 Whenever an entity is inserted or updated, the afterSave callback is invoked. How do I check whether the entity is a newly inserted one? Pseudo code of what I'm trying to do inside the afterSave callback. if newly inserted { dispatch event using the events system; } 回答1: I have got the answer. The answer is as followed: public function afterSave(Event $event, Entity $entity, array $options) { if ($entity->isNew()) { // do whatever you need to do here. } } I hope this helps someone who's new

Confusing Validation vs. Application Rules in CakePHP3

假如想象 提交于 2019-12-12 07:58:32
问题 Multiple questions about validation which may belong together, because they are all kind of adressing the new validation concept in CakePHP 3. I have read the chapters (1, 2, 3) in the cookbook multiple times but honestly I don't understand how to do it the right way. I also know there is currently a issue/discussion at GitHub about the Validation in CakePHP3 which may address the same topic. Validation errors are triggered e.g. with patchEntity. So I would think it is better to ALWAYS check

Cakephp empty Associations on Linking Tables Together

允我心安 提交于 2019-12-12 06:57:30
问题 I want to do this: http://book.cakephp.org/3.0/en/orm/associations.html but it's not working. The cell in my complejo table is empty when I want to show the name of the another model (ciudad name). I want to show the name, not the Id of Ciudad. Here you can see the empty column: Click Me So.. This is my code: ComplejosTable.php <?php namespace App\Model\Table; use App\Model\Entity\Complejo; use Cake\ORM\Query; use Cake\ORM\RulesChecker; use Cake\ORM\Table; use Cake\Validation\Validator; /** *

Login custom route being rejected by Auth

自闭症网瘾萝莉.ら 提交于 2019-12-12 06:15:33
问题 Router::scope('/:club_slug', function ($routes) { $routes->connect('/login', ['controller' => 'Users', 'action' => 'login']); }); So when I'm trying access http://example.com/club-name/login , I'm being redirected to http://example.com/users/login with the flash message You have to login to access this area . Auth loginAction is [controller => 'Users', 'action' => 'login'] , since the custom route that I mentioned at beginning of the question is pointing to the path that is specified at

How can I manipulate translation methods of cakephp 3 to become case insensitive?

a 夏天 提交于 2019-12-12 05:39:42
问题 This is a part of my src/Locale/en_US/default.po file msgid "Acg_id" msgstr "access control group identifier" msgid "acg_id" msgstr "access control group identifier" msgid "Acg_Id" msgstr "access control group identifier" my default.po file is too long. And I think it is impossible to write like this. msgid "Acg_id" msgid "acg_id" msgid "Acg_Id" msgstr "access control group identifier" How can I implement function below in cakephp core function __($token){ $translation = translation

Class 'App\Controller\Debugger' not found error with cakephp ver3

偶尔善良 提交于 2019-12-12 05:39:37
问题 I am using cakephp 3.0.2. I tried to use Debugger::dump($date_taken_year); and encountered the error Error: Class 'App\Controller\Debugger' not found . If I remove the line that uses Debugger::dump() , the error disappears and the controller function runs smoothly. I have checked that inside app.php, I have this line 'debug' => true, . Do I have to do anything else to use Debugger class? I had no problems when using cakephp ver2.x 回答1: It seems, you only forgot to import namespace, proper use

Cakephp 3: React/zmq library namespace

流过昼夜 提交于 2019-12-12 04:25:50
问题 I am working on on the basic tutorial on using ratchet mentioned here http://socketo.me/docs/push. I have created a test setup for the tutorial that works flawlessly. However, when I am trying to integrate the setup with CakePHP 3 I am running into problems. The ratchet and ZMQ servers are independent just the way mentioned in the tutorial. Only the following piece of code needs to move into CakePHP 3 controllers: $context = new ZMQContext(); $socket = $context->getSocket(ZMQ::SOCKET_PUSH,