cakephp-3.0

Cake PhP 3 Saving associated data in multiples levels

↘锁芯ラ 提交于 2019-12-06 10:49:07
问题 I have a data model where I register an user->customer->contactinfo->email/phone Each one of these are different tables with respective controllers and everything associated. When I try to save an user I use the following code: $users = TableRegistry::get('Users'); $user = $users->newEntity($data, [ 'associated' => ['Customers'],['Contactinfos'],['Phones'],['Emails'] ]); $users->save($user); But it only saves the user and the customer. This is the request data: Array ( [customers] => Array (

CakePHP 3 Ldap authentication issue and clarification

本秂侑毒 提交于 2019-12-06 09:22:37
I am working on integrating LDAP authentication in my project. and I followed the tutorial from official CakePHP site that guides through how to create a custom object in application src path and using those custom objects in AuthController. So I created a folder called Auth in src with the file name called LdapAuthorize.php. The path looks like this src/Auth/LdapAuthorize.php Here is my LdapAuthorize.php code: namespace App\Auth; use Cake\Auth\BaseAuthorize; use Cake\Network\Request; class LdapAuthorize extends BaseAuthorize { public function authorize($user, Request $request) { if ($user ==

CakePHP 3 Multiple Databases

故事扮演 提交于 2019-12-06 09:03:46
问题 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

CakePHP 3.x checkbox formatting issue

China☆狼群 提交于 2019-12-06 07:23:58
问题 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

CakePHP 3.7.3: Use SecurityComponent with Ajax with SPA

耗尽温柔 提交于 2019-12-06 06:36:47
This is a classic issue with ajax request with enabled SecurityComponent. I have mainly a SPA. That's the main problem. I'm using also the CSRF component, which works fine: const response = await axios.post("/items/add.json", data, { headers: {"X-CSRF-Token": "<?= $this->getRequest()->getParam('_csrfToken') ?>"} }); What doesnt work is to send the _Token for the security component: {message: "'_Token' was not found in request data.", url: "/.../add.json", code: 400,…} Of course I can disable the SecurityComponent. I don't need a form/form-helper for my request, then the question is if it makes

CakePHP 3.x - AuthComponent::user() in View

我与影子孤独终老i 提交于 2019-12-06 00:06:08
问题 In CakePHP 2.x you could do AuthComponent::user() in View to get data from Auth component. In CakePHP 3.0beta3 it throws: "Error: Class 'AuthComponent' not found" Is there a simple way to get data from AuthComponent in View? 回答1: Cake 3.5 In AppController : public function beforeRender(Event $event) { .... $this->set('Auth', $this->Auth); } In .ctp template: <?php if (!$Auth->user()) { ?> <a class="login" href="<?php echo $this->Url->build($Auth->getConfig('loginAction')); ?>">Login</a> <?php

Upload files using cakephp 3 and store it in a blob

浪尽此生 提交于 2019-12-05 23:15:07
I know that storing files in database is a little dirty, but I'm need to upload and store a file into a database BLOB and I haven't found any documentation about it and I haven't find any clue, so any help about it will be appreciated. Thanks in advance, David There is nothing special that you'd need to do, simply set the data that you want to store in the appropriate entity property (respectively array key), either as a string, or as a stream. BLOB columns will automatically be associated with the \Cake\Database\Type\BinaryType database type , where everything that is necessary for storing

i18n translation with CakePHP 3

怎甘沉沦 提交于 2019-12-05 21:35:59
Context I want to translate my app in french and english. I followed exactly the CakePHP 3 documentation but it is not working. What I did so far For my development, I'm using a vagrant box to easily get up and running with CakePHP 3. This box is named vagrant-chef /config/bootstrap.php I modified the line 100 to use french as the default language. ini_set('intl.default_locale', 'fr_CA'); /src/Controller/PagesController I added this method to the default PagesController public function initialize() { I18n::locale('en'); } /src/Template/Pages/home.ctp I added these 2 lines <?php echo __('Hey,

Check if object exists or is empty in view template

一世执手 提交于 2019-12-05 20:12:06
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> <?php foreach ($articles as $article): ?> <tr> <td><?= $article->id ?></td> <td> <?= $this->Html->link(

Cakephp 3 : How to receive get request data?

泪湿孤枕 提交于 2019-12-05 19:40:57
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 ? Balkrushna Maheta Used below code in product controller if ($this->request->is(['get'])) { $search = $this->request->query