cakephp-3.0

How to get SQL Query on model->save() in CakePHP 3?

不问归期 提交于 2019-12-23 10:43:08
问题 How can I view the SQL Query on model->save() in CakePHP 3? Is there any way to do this? I want to get the specific sql query e.g when I save new entity. I need it because I want to save that to a log file in some cases. My bootstrap.php log config: Log::config('current', [ 'className' => 'File', 'path' => LOGS.DS.date('Y-m').DS, 'scopes' => ['daily','queriesLog'], 'file' => date('Y-m-d'), ]); What i want to get: e.g when i save entity: $this->Clients->save($client); i want to log something

How should I use requestAction in the view with CakePHP 3.x

南楼画角 提交于 2019-12-23 05:11:34
问题 My code: // View/Activities/index.ctp ... <div> <?php echo $this->requestAction('/Activities/ajax_list/'.$categoryId,['return']);?> </div> ... //View/Activitest/ajax_list.ctp .... <?php echo $this -> Html -> image("/img/add1.jpg"); ?> ... <?php echo $this->Html->link('add_project', array('controller'=>'projects', 'action'=>'add', $categoryId)); ?> .... I want to include the view 'ajax_list' into the 'index',and it has been displayed but the url of image and link was wrong. Then I debug the

Update a HasMany records

醉酒当歌 提交于 2019-12-23 05:07:52
问题 I am converting a working app from cakephp2 to cakephp3. I'm struggling to get a form that updates hasMany records to work. The app has the following structure: MODELS: use Cake\ORM\Table; use Cake\Validation\Validator; class AwardsTable extends Table { public function initialize(array $config) { $this->hasMany('Levels', ['sort' => 'sort_order']); } } namespace App\Model\Entity; use Cake\Auth\DefaultPasswordHasher; use Cake\ORM\Entity; class Award extends Entity { protected $_accessible = [

Cakephp select from where jquery null

谁说我不能喝 提交于 2019-12-23 05:04:07
问题 Here are my Code: <div class="dropdown-menu" aria-labelledby="navbarDropdown"> <a class="dropdown-item" id="animal" value="1">Animal1</a> <a class="dropdown-item" id="animal" value="2">Animal2</a> <a class="dropdown-item" id="animal" value="3">Animal3</a> </div> I have an jQuery one click: $(document).ready(function() { $("a#animal.dropdown-item").click(function() { var animalvalue = $(this).attr("value"); $.ajax({ type: 'POST', url: "/mycontroller/", data: {animalvalue:animalvalue}, cache:

CakePHP 3: Contain Deep Associated Model with COUNT()

邮差的信 提交于 2019-12-23 04:52:20
问题 I have the following related table objects: SettingsTable belongsTo SettingsHeadersTable SettingsHeadersTable hasMany SettingsTable SettingsOptionsTable belongsTo SettingsTable SettingsTable hasMany SettingsOptionsTable For example: There is a header titled "General Site Settings". There is a setting under that header titled "Offline Status". There are 3 options under that setting for "Online", "Offline (restricted)" on "Offline (unrestricted)" I have a controller that I would like to find

How to retrieve information when linking models through a table in CakePHP 3.0?

假如想象 提交于 2019-12-23 04:24:23
问题 I'm trying to set up a user access model based on the one in the CakePHP blog tutorial (http://book.cakephp.org/3.0/en/tutorials-and-examples/blog-auth-example/auth.html), but with Roles in a separate table, and linked to users by a UserRoles table. I currently have the following in Model/Table/UsersTable.php: $this->belongsToMany('Roles', [ 'through' => 'UserRoles' ]); and the following in Model/Table/RolesTable.php: $this->belongsToMany('Users', [ 'through' => 'UserRoles' ]); and the

cakephp 3.0 get values in two columns as one

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-23 02:59:14
问题 I am trying to get multiple of two columns as value but in cakephp 3.0 it given a error Error: SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'AS (Transactions__amount * PluTransaction FROM transactions Transactions LEF' $result = $this->Transaction->find('all', array( 'conditions' => [ 'Transactions.house_id' => $houseId] ))->join([ [ 'alias' =>

How can I join two tables on multiple columns in CakePHP 3?

大城市里の小女人 提交于 2019-12-23 01:19:20
问题 I'm using CakePHP v3 I have a table that looks like this: Document: id | section | paragraph ------------------------- 1 2 4 Text: id | section | paragraph | theText --------------------------------------- 12 2 4 Blah blah So in SQL I could do something like this; SELECT * FROM document INNER JOIN text ON document.section=text.section AND document.paragraph=text.paragraph How can I do something like this in CakePHP using the ORM? The Primary key in both tables is set up to be the id column. I

Check if object exists or is empty in view template

╄→尐↘猪︶ㄣ 提交于 2019-12-22 09:45:38
问题 How do you check within the view template if the result object contains any entries? (There was a similar question already, but this one is slightly different) Take the CakePHP 3 blog tutorial for example. They show how to list all articles on one page: // src/Controller/ArticlesController.php public function index() { $this->set('articles', $this->Articles->find('all')); } And the view template: <!-- File: src/Template/Articles/index.ctp --> <table> <tr> <th>Id</th> <th>Title</th> </tr> <

CakePHP 3: find() with cache

好久不见. 提交于 2019-12-22 09:25:46
问题 About the get() method, I read here: Like find() get has caching integrated. You can use the cache option when calling get() to perform read-through caching But later, in the section dedicated to the find() method (here), the cache is not mentioned, there are no examples for the cache and the cache option is not mentioned among the supported options. So I would like to know: can I use the cache option with the find() method? If so, how? Thanks. Thanks to ndm. So: $query = $this->Pages->find(