cakephp-3.0

Cakephp 3 loading vendor files

只愿长相守 提交于 2019-12-05 02:23:06
问题 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 回答1: Vendor files are 3rdparty files. You custom static utility classes are not vendor files but rather your app files. You can put

cakephp3 Class DateTime not found

半腔热情 提交于 2019-12-05 00:45:18
I'm trying to convert my cakephp plugin from 2.X to 3. I have a little problem inside my component plugin at this line: $dStart = new DateTime($now); //$now = date('Y-m-d H:i:s'); return me this error: Error: Class 'CurrencyConverter\Controller\Component\DateTime' not found Seems that it search DateTime inside my plugin directory. How can I solve it? Thanks Try: $dStart = new \DateTime($now); because CakePHP 3.0 using namespaces and if you not add a root namespace it will be looking for class under current namespace. 来源: https://stackoverflow.com/questions/29500225/cakephp3-class-datetime-not

How to execute custom query in cakephp 3.x

左心房为你撑大大i 提交于 2019-12-04 23:35:29
问题 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. 回答1: 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

CakePHP 3 - Query builder properly not working for HasMany associations

烈酒焚心 提交于 2019-12-04 20:48:02
Table : Services +-----+--------------+ | id | title | +-----+--------------+ | 1 | Service 1 | +-----+--------------+ | 2 | Service 2 | +-----+--------------+ Table : Workshops { HasMany WorkshopServices } +-----+---------------+ | id | title | +-----+---------------+ | 1 | Workshop 1 | +-----+---------------+ | 2 | Workshop 2 | +-----+---------------+ Table : WorkshopServices +-----+--------------+-------------+ | id | workshop_id | service_id | +-----+--------------+-------------+ | 1 | 1 | 1 | +-----+--------------+-------------+ | 2 | 1 | 2 | +-----+--------------+-------------+ I want to

Catch Exception in Cakephp 3 : not working

隐身守侯 提交于 2019-12-04 18:19:56
问题 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"

How do you get the last insert ID in CakePHP 3.0?

*爱你&永不变心* 提交于 2019-12-04 15:54:33
问题 Working with the CakePHP 3.0 beta, seems like a simple problem, but I've searched through the docs and can't find anything. After inserting a new record using $this->Model->save(), I'd like to the get the auto_increment primary key ID of the newly created record. With Cake 2.x, I could do: $record_id=$this->ModelName->id; or $record_id=$this->ModelName->getLastInsertID(); However neither of those seems to work in CakePHP 3.0. Thanks 回答1: Finally found the answer, if anybody else runs into

CakePHP 3 Multiple Databases

感情迁移 提交于 2019-12-04 14:34:02
I want to connect to a second (remote) database using CakePHP 3. I have found solutions online that suggest how to associate different models with different databases but that is not what I need to achieve. I need to be able to connect to a remote database (that is not associated with any model) and read/write some records from an action in my controller. Can this be achieved using CakePHP? Edit (more information): I have a website that acts as a booking platform for hotel rooms. The availability of these rooms can be controlled via my website and stored in my database. But for some clients I

CakePHP 3.x checkbox formatting issue

ぐ巨炮叔叔 提交于 2019-12-04 14:15:38
This may seem obvious to some of you, but I really am struggling to find a straight answer. I've generally googled, as well as read both the CakePHP manual and the API for an answer to the following question: When creating an input, the following code creates the following outputs: // in the view echo $this->Form->input('notes'); // resultant html <div class="input textarea"> <label for="notes">Notes</label> <textarea id="notes" rows="5" name="notes"></textarea> </div> Note: this is consistent across most input types; and because it's consistent it's great for formatting. However, with a

ORDER BY on MySQL stored function in CakePHP 3

笑着哭i 提交于 2019-12-04 12:25:42
I'm working on cakePHP 3. I have a user defined function(UDF or Routine) in mysql database. That function takes a parameter and returns an integer value. I have to order that returned value in MySQL order clause. I know mysql query to use that function. i.e, SELECT customer_id FROM table_name ORDER BY routine_name(param1); //param1 is 'customer_id' which I have written after SELECT But I don't know that how to build this query in cakePHP 3. If anyone knows the solution, answer will be appreciate. Here is my cakePHP 3 code. $purchasesTable = TableRegistry::get("Purchases"); $query =

What version of Foundation is used in cakePHP3?

做~自己de王妃 提交于 2019-12-04 12:19:24
From an earlier question ( Responsive bootstrap designing in CakePHP 3x ) I understand that cakePHP3 are using Foundation for front-end framework, but which version (in cakePHP v.3.2)? I'm struggling with a toggled top-bar, that won't open when minimized. There seems to have been some bugs in the 5th version and I'm now wondering if they aren't fixed in the version that cakePHP3 are using. The CakPHP application templates base.css file was last updated with foundation on September the 1st of 2015 https://github.com/cakephp/app/commit/3bf179e04d48c859b4ba411d81607ae25d275b3b As far as I can