cakephp-3.0

Cakephp 3 : How to receive get request data?

喜欢而已 提交于 2019-12-10 10:25:06
问题 I have written ajax to send search key, I have tried below code $.ajax({ method:'GET', url:'<?php echo Router::url(['action' => 'product_search']); ?>', data:{search:search}, success: function(data) { $('.fetch-data').html(data); } }); Then I have received it in product controller like if ($this->request->is(['get'])) { $search = $this->request->data('search'); } Here $search is null. If I use POST in here then it's working fine. How can I receive this data by get method ? 回答1: Used below

Pass extra data to finder auth

只愿长相守 提交于 2019-12-10 02:34:10
问题 My finder from Auth has conditions that I need to access $this->request but I don't have access for that on UsersTable . AppController::initialize $this->loadComponent('Auth', [ 'authenticate' => [ 'Form' => [ 'finder' => 'auth', ] ] ]); UsersTable public function findAuth(Query $query, array $options) { $query ->select([ 'Users.id', 'Users.name', 'Users.username', 'Users.password', ]) ->where(['Users.is_active' => true]); // If i had access to extra data passed I would use here. return

cakephp3 Class DateTime not found

醉酒当歌 提交于 2019-12-10 02:22:41
问题 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 回答1: Try: $dStart = new \DateTime($now); because CakePHP 3.0 using namespaces and if you not add a root namespace it will be looking for

Connect with multiple database in CakePHP 3

戏子无情 提交于 2019-12-09 20:21:28
问题 I want to store some data histories and logs in other database table it may be very large database in terms of records in future. Also cross database SQL joing should be supported. So please help me for solution for this. Thanks in advance 回答1: You have follow below steps fo use multiple datasource within same cakephp application. Mention multiple database source in Config/app.php You have to manage multiple data source configurations, in default data source keep main database, and make one

CakePHP 3.0: How to do an insert on duplicate key update?

风格不统一 提交于 2019-12-09 17:56:01
问题 I have an array $articles like this [ (int) 0 => [ 'id' => '-@940039', 'xe_dsca' => 'ÜP2768G/1', 'xe_citg' => '1F0200', 'xe_cuni' => 'stk', 'xe_seak' => 'ÜP2768G/1', 'xe_seab' => '', 'xe_wght' => '0.0153', 'xe_cwun' => 'kg', 'xe_wgap' => '2', 'xe_seri' => '2', 'xe_ltct' => '2', 'xe_qual' => '2', 'xe_hama' => '2', 'xe_ctyo' => 'DE', 'xe_ccde' => '85045095', 'xe_cpln' => '240000', 'xe_spar' => '2', 'xe_wear' => '2', 'xe_ctyo_de' => null, 'xe_cean' => null, 'xe_ewm_dsce' => null, 'xe_cood' =>

How to read and write Session in Cakephp 3.0

不打扰是莪最后的温柔 提交于 2019-12-09 04:45:01
问题 I am new to cake 3.0. I have read documentation on http://book.cakephp.org/3.0/en/development/sessions.html But I am not able to write sessions. use Cake\Network\Session\DatabaseSession; $session->write('Config.language', 'eng'); $session->read('Config.language'); 回答1: You need to set $session : $session = $this->request->session(); $session->write('Config.language', 'eng'); $session->read('Config.language'); And then you'll be able to read and write in your session Or you can direclty read

How to select a specific field additionally to a tables default fields?

我的梦境 提交于 2019-12-09 03:36:13
问题 I an looking to use a JOIN to select data from a table and a view in CakePHP like so : $this->Annonces->find('all') ->where($arrFiltres) ->order($arrOrder) ->join([ 'table' => 'annonces_suivis', 'alias' => 'AnnoncesSuivis', 'conditions' => [...], ]); And would like to be able to select all the fields from the first table and som of the jointed table like so : ->select(['Annonces.*', 'AnnoncesSuivis.id']); But this creates a faulty SQL query. 回答1: .* isn't supported by the ORM Query, it will

CakePHP 3 contain select fields

房东的猫 提交于 2019-12-08 19:23:18
问题 I have the following DB tables: items, users, groups, itemImages. There are many to many relations between (items, groups) and (users, groups), and one to many between (items, itemImages). All the appropriate foreign keys have been setup in CakePHP as associations. How can I construct a query with contain() which selects all items and their main image, which are in a group which has been assigned as a main group to a user with a particular id? To make it clearer, here is what a plain SQL

Adding pagination value to json response in Cakephp 3.3

若如初见. 提交于 2019-12-08 18:50:39
I am trying to add the number of pages paginated value to the json response for Cakephp 3.3. I followed the Cakephp 3.3 documentation to make queries using the paginator method and activated the json extension where you just have to add .json to the end of your controller and the function to get a json response. The results I get are the first page of pagination, however I'd like to add a parameter before that tells me how many pages have been paginated so that I can show how many more pages can be continued to. Example of the json response i am trying to get is below with pages being the

Integrate Wordpress Post with Cakephp3

戏子无情 提交于 2019-12-08 16:15:57
问题 I am working on cakephp 3.x and want to display blogs section on my site. I want to use WordPress feature in my site. I have installed WordPress 4 on my local server, then I have imported tables of WordPress into cake's database and put the WordPress folder into webroot folder of Cakephp. In app controller's initialize() function I have put this code as follows: global $wpdb; define('WP_USE_THEMES', false); require($_SERVER['DOCUMENT_ROOT']."/webroot/blog/wp-config.php"); So that I can embed