cakephp-3.0

Multiple Associations to the Same Model in CakePHP 3

我只是一个虾纸丫 提交于 2019-12-04 11:08:49
问题 I am using cakePHP version 3.x. When i query the MessagesTable i want to get the Users data for the the sender and the receiver of the message. I have done this many times in cakePHP 2 but i cant figure out why it isn't working in version 3.x. i have a UsersTable and a MessagesTable. UsersTable $this->hasMany('Messages'); MessagesTable $this->belongsTo('Users', [ 'foreignKey' => 'sender_id', 'propertyName' => 'Sender', ]); $this->belongsTo('Users', [ 'foreignKey' => 'user_id', 'propertyName'

cakephp 3.x saving multiple entities - newEntities

谁说我不能喝 提交于 2019-12-04 10:04:41
I'm having the hardest time with saving multiple records. I've tried a million things, but I end up with the same problem: my records are not saved and I can't see any errors. Bear in mind that I'm new to cakephp and a novice coder. Am I missing something obvious and crucial? Table: $this->table('splits'); $this->displayField('id'); $this->primaryKey('id'); $this->belongsTo('Transactions', [ 'foreignKey' => 'transaction_id', 'joinType' => 'INNER' ]); $this->belongsTo('Accounts', [ 'foreignKey' => 'account_credit_id', 'joinType' => 'INNER' ]); Controller: $splits = $this->Splits->newEntity();

Authorization and ACL in cakephp 3

旧城冷巷雨未停 提交于 2019-12-04 08:38:51
问题 I search the document but I don't find anything about ACL implementation in cakephp 3. How can I implement authorization with ACL in cakephp 3? 回答1: ACL is not built into CakePHP 3 as it was in CakePHP 2. It is now available as a separate plugin. Quote from http://book.cakephp.org/3.0/en/appendices/3-0-migration-guide.html ACL related classes were moved to a separate plugin. Password hashers, Authentication and Authorization providers where moved to the \Cake\Auth namespace. You are required

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

泄露秘密 提交于 2019-12-04 07:42:11
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' => null, 'xe_ewm_dsne' => null, 'xe_ewm_dsge' => null, 'xe_ewm_dsen' => null, 'xe_ewm_dscz' => null, 'xe

cakePHP 3.0 and bootstrap glyphicons

99封情书 提交于 2019-12-04 06:55:21
问题 I want to add glyphicons instead of text in my index, add, edit views. This works in the index.ctp <?= $this->Html->link(__('<i class="glyphicon glyphicon-pencil"></i>'), ['action' => 'edit', $user->user_id], array('escape' => false)) ?> But when I do it for the delete action it shows me the glyphicon but it doesn't give me the 'Are you sure you want to delete the user?' anymore <?= $this->Form->postLink(__('<i class="glyphicon glyphicon-minus"></i>'), ['action' => 'delete', $user->user_id],

Using CakePHP 3.0 plugin

徘徊边缘 提交于 2019-12-04 06:19:29
问题 I'm currently building a new CakePHP app with version 3.0.0-RC1, and trying to install and use the jasig/phpCAS plugin. Using this guide, I've run the following command from the command prompt: composer require jasig/phpcas This correctly copies the jasig/phpcas files into the vendor directory of my app, but one of the other files that the guide says should be updated (vendor/cakephp-plugins.php) doesn't even exist. I've had a tough time accessing the plugin. I want to be able to call its

CackePHP 3 formatResults() ORDER by field created dynamically

痞子三分冷 提交于 2019-12-04 06:04:10
问题 I wish to sort on a field that I dynamically creates in formatResults() $users = $this->Users ->find('all') ->formatResults(function ($users) use ($lat, $lng) { return $users->map(function ($user) use ($lat, $lng) { $user->distance = getDist($lat, $lng); return $user; }); }) ->order([ 'distance' => 'ASC' ]); [...] $this->set('users', $this->paginate($users)); The field $user->distance is not in the database. $user->distance contains a float ( getDist($lat, $lng); ) that is variable depending

CakePHP SQLSTATE[HY000][14] error

不问归期 提交于 2019-12-04 05:58:14
I'm trying to upgrade my current CakePHP 2.x application to 3.x. I fixed namespace and folder structure issues. Now I have problems with database. In my test server, I created same MySQL database and grant access to users. Then I changed config\app.php configuration file. But when I try my application I get following error. What would be the problem ? It seems like Cakephp tries to use Sqlite but I use MySQL ? Inside config\app.php 'Datasources' => [ 'default' => [ 'className' => 'Cake\Database\Connection', 'driver' => 'Cake\Database\Driver\Mysql', 'persistent' => false, 'host' => 'localhost',

CakePHP 3 - Where is custom datasource?

本秂侑毒 提交于 2019-12-04 04:53:22
问题 I have a large number of CakePHP 2 web applications, many of them use remote data over the custom DataSource. I'm reading the documentation of CakePHP 3, but I can not find instructions for creating custom datesource. My next project also requires a custom DataSource (ArangoDB), so I planned to build it with the new version of CakePHP. Please do specify where and how to build a DataSource in CakePHP 3. Thank You. 回答1: Just look at the code of any existing database driver and see how it is

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

不问归期 提交于 2019-12-04 04:21:55
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? 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 } else { ?> <div class="name"><?php echo h($Auth->user('name')); ?></div> <?php } ?> mario741 In View: