cakephp-3.0

Truncating table before seeding in cakephp

泄露秘密 提交于 2019-12-25 09:27:04
问题 I'm wondering if there is a better (more smooth) way to disable foreign key checks, truncate table, insert data and enable foreign key checks when you seed database with cakephp 3. This is my current code which is not working <?php use Migrations\AbstractSeed; use Cake\Datasource\ConnectionManager; /** * Categories seed. */ class CategoriesSeed extends AbstractSeed { public function run() { $connection = ConnectionManager::get('default'); $connection->execute('SET FOREIGN_KEY_CHECKS = 0');

Hidden fields are still listed from database in cakephp 3

不羁岁月 提交于 2019-12-25 08:49:21
问题 I am getting the records from my database in two different points, using "get" and "find" methods. The problem is that when I am using "get", "first" or "last" the hidden fields aren't displayed (Its ok), but when I am using "find" they are still there. <?php //My Plugin in /plugins/Comunica/Files/src/Model/Entity/File.php namespace Comunica\Files\Model\Entity; use Cake\ORM\Entity; class File extends Entity { protected $_hidden = ['password']; protected $_virtual = ['protected']; protected

CakePHP 3 and partial View update via Ajax - How it should be done?

蹲街弑〆低调 提交于 2019-12-25 08:48:10
问题 One more time I have bumped into the problem how partial view upadtes via ajax should be done in CakePHP3. From my point of view, there are 3 ways of doing this: Render required part of the view in dedicated controller action and simply inject the HTML. Create dedicated template (*.ctp) file for every ajax action, render it like any other action but without the main layout and inject the HTML (kind of variant 1 but with separated VC logic). Return only required data as an ajax response (eg.

How to set aliases and then still affect the return type for queries in json formats for Cake 3.x?

吃可爱长大的小学妹 提交于 2019-12-25 07:53:46
问题 Situation Using cake 3.2.4 and the plugin Crud 4.2 for the purpose of producing an API feed What code did I use at first? $this->Crud->on('beforePaginate', function(Event $event) use ($conditions) { $this->paginate['conditions'] = $conditions; $this->paginate['limit'] = 100; $this->paginate['fields'] = [ 'id', 'title', 'start_date', 'end_date', 'revenue', 'total_costs', 'collections' ]; }); What am I getting as json feed? "success": true, "data": [ { "id": 789, "title": "9143 - Asia Summit",

Using an alias in my Apache's httpd.conf to point to a cakephp 3.0 directory results in error 404

白昼怎懂夜的黑 提交于 2019-12-25 07:29:30
问题 On my CentOS LAMP. I have a website, www.mydomain.com. In my httpd.conf I have: <VirtualHost *:80> ServerAdmin me@myemail.com DocumentRoot /var/www/cakephp ServerName www.mydomain.com <Directory /var/www/cakephp/> Options FollowSymLinks AllowOverride All </Directory> </VirtualHost> So www.mydomain.com is served from /var/www/cakephp. But I want it so that URL "www.mydomain.com/powercontroller/" is served from: /var/www/powercontroller. So I put this alias into httpd.conf as well: Alias

CakePHP 3.x - SUM() on ManyToMany

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-25 07:19:04
问题 I am getting stuck on using SQL functions queries made in CakePHP 3 in combinations with associations. The situation is as follows: I have three tables, a 'products' table, an 'orders' table and a join table called 'orders_products'. In the index of OrdersController I would like to add the total price (= sum of relevant product prices) to the table of orders. In SQL this exactly can be done with the following query: SELECT orders.id, SUM(products.price) FROM orders LEFT JOIN orders_products

How to use telegram api package in CakePHP 3?

余生长醉 提交于 2019-12-25 05:04:53
问题 I tried to use PHP telegram bot in my CakePHP 3 website, but encountered many problems. done I ran "composer require longman/telegram-bot" and copied package to "plugins" folder. and then "bin/cake plugin load longman/telegram-bot". questions 1. Where I must put the package and why? vendor or plugins 2. How to call package methods in URL? I added "index" method to "telegram-bot/src/Telegram.php" and tried this snippet code in my "Template/Users/index.ctp". echo $this->Html->link('telegram', [

How to find field through foreign key in cakephp3.x.x?

雨燕双飞 提交于 2019-12-25 04:42:43
问题 how to try like this, i already write in ItemsTable.php like this public function initialize(array $config) { $this->belongsTo('Categories', [ 'className' => 'Item', 'foreignKey' => 'cid', 'propertyName' => 'name' ]); } How do I display category name instead of Cid ? 来源: https://stackoverflow.com/questions/27718675/how-to-find-field-through-foreign-key-in-cakephp3-x-x

How to make cakephp 3 url ready for marketing?

不羁的心 提交于 2019-12-25 01:54:32
问题 I am new for cakephp. I am trying to rewrite the url to make it SEO friendly. I have create module in cakephp3 for cms page. Page Table - url field would like to use as "about-us" CREATE TABLE IF NOT EXISTS `pages` ( `id` int(11) NOT NULL, `title` varchar(100) NOT NULL, `detail` text NOT NULL, `url` varchar(225) NOT NULL, ) ENGINE=InnoDB AUTO_INCREMENT=14 DEFAULT CHARSET=latin1; Current URL (working)- https://example.com/pages/view/8 I want to make this like below. https://example.com/about

Saving Additional Data to the Join Table in the add method in CakePHP 3.0

拟墨画扇 提交于 2019-12-25 00:14:14
问题 In this example from the book: https://book.cakephp.org/3.0/en/orm/associations.html#using-the-through-option class StudentsTable extends Table { public function initialize(array $config) { $this->belongsToMany('Courses', [ 'through' => 'CoursesMemberships', ]); } } class CoursesTable extends Table { public function initialize(array $config) { $this->belongsToMany('Students', [ 'through' => 'CoursesMemberships', ]); } } class CoursesMembershipsTable extends Table { public function initialize