cakephp-3.0

$this->set('title', 'Title Name'); not working in CakePHP 3.x

帅比萌擦擦* 提交于 2019-12-04 00:42:29
问题 Basically in default.ctp I have this for my title: <title> <?= $this->fetch('title') ?> </title> And inside of the controller I have this line: $this->set('title', 'Test-Title'); But it does nothing, it still displays controllers name(Jobs, controllers full name os JobsController.ctp) But if I put this inside of my view file: $this->assign('title', 'Test-Title'); It changes the title. So what is wrong with $this->set('title', $title) ? 回答1: You can just set() the variable in your controller:

CakePHP 3.x - Load CSS in head tag for a specific action

我与影子孤独终老i 提交于 2019-12-03 18:12:09
问题 So far I can only load a specific CSS file for a specific action by include that CSS file within <body> tag from the corresponding view file. But I want to include that CSS file within <head> tag when a specific action is called? 回答1: In your template, this can be achieved by linking to the css file using the block option: Creates a link(s) to a CSS style-sheet. If the block option is set to true, the link tags are added to the css block which you can print inside the head tag of the document

Cakephp 3.x: SQLSTATE[HY000]: General error: 11 database disk image is malformed

十年热恋 提交于 2019-12-03 17:38:55
问题 I'm getting this error when I upload my application to linux. This is working fine on my local windows system but gives me error on linux server. When I search regarding this then I found this is sqLite related issue. If this is sqLite issue then how can I change this to MySQL. Please help me. 回答1: Delete the /tmp/debug_kit.sqlite 回答2: Delete the tmp folder Delete the /tmp/* if you are getting further permission issue the set 777 permission to cakephp folder chmod -R 777 bookmarker 回答3:

Cakephp 3 loading vendor files

我是研究僧i 提交于 2019-12-03 17:31:15
In cakephp 2 when I need a vendor or related class to be loaded globally, i was adding require or app use inside bootstrap.php ot core php. In cakephp 3 where should I require vendor files ? I dont want to declare vendor require in every class and template file that I use my vendor files. http://book.cakephp.org/3.0/en/core-libraries/app.html#loading-vendor-files Vendor files are 3rdparty files. You custom static utility classes are not vendor files but rather your app files. You can put them under src/Lib/ . Just ensure to use proper namespace for the classes and add proper use statement

Cakephp 3 multiple custom template formhelpers

本小妞迷上赌 提交于 2019-12-03 14:33:27
问题 So I'm at work (working with sensitive data might I add for posterity's sake), and the powers that be decide we need to use the all powerful and least documented new tool by Cakephp 3.0 (beta at this time). Edit: My goal is to create several different templates for forms to call through the formhelper template or input methods. There really isn't much of an a good example for this. Customizing the Templates FormHelper Uses: As seen in the book(and nowhere else on the internet anywhere) the

Virtual fields with Cakephp 3

独自空忆成欢 提交于 2019-12-03 14:21:06
I need to have a virtual property in my user entity. I followed the CakePHP book . UserEntity.php namespace App\Model\Entity; use Cake\ORM\Entity; class User extends Entity { protected $_virtual = ['full_name']; protected function _getFullName() { return $this->_properties['firstname'] . ' ' . $this->_properties['lastname']; } } In a controller $users = TableRegistry::get('Users'); $user = $users->get(29); $firstname = $user->firstname; // $firstname: "John" $lastname = $user->lastname; // $lastname: "Doe" $value = $user->full_name; // $value: null I followed exactly the book and I only get a

How to execute custom query in cakephp 3.x

你。 提交于 2019-12-03 14:20:33
Custom query execution in cakephp. I have applied below code. $conn = ConnectionManager::get('default'); $rs = $conn->query('SELECT * FROM customers'); It gives me blank array though customers table has 20 records. Please suggest me some solution. Thanks. MSS It's not recommended but somtimes there is no other way! : You should mention namespace of connection manger use Cake\Datasource\ConnectionManager; Get/initialize a connection $conn = ConnectionManager::get('default'); Execute SQL with something like this $stmt = $conn->execute('SELECT * FROM customers'); Fetch the results $results =

CakePHP 3 REST API + CORS Request and OPTIONS method

随声附和 提交于 2019-12-03 14:16:06
I am working on a REST API using CakePHP 3. I want to enable it publicly, so anyone can mane a call to API. So, I have added cors headers as defined here: http://book.cakephp.org/3.0/en/controllers/request-response.html#setting-cross-origin-request-headers-cors I have implemented the EventListener on Dispatcher.beforeDispatch and Dispatcher.beforeDispatch to prepare the cors headers. class ApiResponseHeaders implements EventListenerInterface { /** * Event bindings * * @return array */ public function implementedEvents() { return [ 'Dispatcher.beforeDispatch' => [ 'callable' => 'beforeDispatch'

Confusing Validation vs. Application Rules in CakePHP3

蓝咒 提交于 2019-12-03 13:09:55
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/display errors BEFORE doing the save action: // src/Controller/UsersController.php public function

Catch Exception in Cakephp 3 : not working

蓝咒 提交于 2019-12-03 11:58:30
I try to catch exceptions in Cakephp v3.0, but it doesn't seems to work : try{ $email = new Email('default'); $email->from([Configure::read('email') => Configure::read('emailName')]) ->to(Configure::read('email')) ->bcc($to) ->subject(__('XXXX') . ' : ' . __('XXXX')) ->template('fail', 'default') ->emailFormat('html') ->send(); } catch (Exception $ex) { } It doesn't catch the exception : Could not send email: mail(): Failed to connect to mailserver at "localhost" port 25, verify your "SMTP" and "smtp_port" setting in php.ini or use ini_set() Cake\Network\Exception\SocketException Pretty