cakephp-3.1

Confusing Validation vs. Application Rules in CakePHP3

假如想象 提交于 2019-12-12 07:58:32
问题 Multiple questions about validation which may belong together, because they are all kind of adressing the new validation concept in CakePHP 3. I have read the chapters (1, 2, 3) in the cookbook multiple times but honestly I don't understand how to do it the right way. I also know there is currently a issue/discussion at GitHub about the Validation in CakePHP3 which may address the same topic. Validation errors are triggered e.g. with patchEntity. So I would think it is better to ALWAYS check

How to select only those records that have at least one associated record?

痞子三分冷 提交于 2019-12-12 03:24:09
问题 I have the following associations: Orders belongsTo Sites I execute the following query: $sites = $this->Sites->find('all') ->select(['id', 'name']) ->contain([ 'Users' => function ($q) { return $q->select(['id', 'owner_id', 'firstname', 'lastname']); }, 'Orders' => function ($q) { return $q->where(['status >' => 0]); }, 'Orders.Agplans' ]) ->matching('Users', function ($q) use($owner_id) { return $q->where([ 'Users.owner_id' => $owner_id ]); }) ->all(); But most of the sites have no orders

Cakephp 3 callbacks, behaviors for all models

▼魔方 西西 提交于 2019-12-11 20:12:34
问题 I just started reading cakephp 3 docs (I have been developing with cake 2.x for some time) and want to migrate some website from 2.x to 3. In cake 2 in my AppModel I have some callbacks, particularly beforeFind and beforeSave , that contain some logic concerning almost all tables in a database. Now in cake 3 there is no AppModel , how do I get the same thing done ? The best I can think of is to put that code in some behavior's callbacks, but I have like 30 models, should I load the behavior

CakePHP 3.1 : My validation for translate behaviour fields, need some help in review/comment

别来无恙 提交于 2019-12-11 10:33:27
问题 I have worked on a hook for validate my translated fields, based on this thread : https://stackoverflow.com/a/33070156/4617689. That i've done do the trick, but i'm looking for you guys to help me to improve my code, so feel free to comment and modify class ContentbuildersTable extends Table { public function initialize(array $config) { $this->addBehavior('Tree'); $this->addBehavior('Timestamp'); $this->addBehavior('Translate', [ 'fields' => [ 'slug' ] ]); } public function validationDefault

Is it possible to use AppController on error pages? (Cakephp 3.1)

ぐ巨炮叔叔 提交于 2019-12-10 18:33:28
问题 I am trying to render error templates (eg error400.ctp) but with the default layout (site header and footer) which relies on components and variables set in AppController. How do I tell Cake to use AppController when rendering error pages? I have already tried making an ErrorController which extends AppController, but it breaks for missing actions. 回答1: Here's my working ErrorController in case anyone comes looking for it: <?php namespace App\Controller; use App\Controller\AppController; use

Session destroyed out of nowhere in PHP

旧街凉风 提交于 2019-12-10 14:47:31
问题 I am experiencing issue with a session being destroyed out of nowhere: session_start(): Failed to decode session object. Session has been destroyed . Kind of impossible to replicate the issue since I got this thrown in my server log. Any ideas what could be the roots of that problem and/or where to start because I am getting that very rare (almost never). 回答1: This happened to me when I was storing too much in $_SESSION where they were saved using serialize() in a table. Solution: don't store

How to check CSRF token using AJAX and CakePHP 3 when user is not logged in?

半城伤御伤魂 提交于 2019-12-10 11:47:04
问题 So I made my site live and I am entering into the public realm where people aren't always nice. I just started learning about CSRF and saw that it was something I needed when I made my cakephp 3 site live. As seen here! I added the csrf component and the security component to my site, but I have 1 major problem. Now, when users want to sign up they can't. I use a custom form for stripe to send payment, but also add a user using ajax to my database. The user gets added first and then the

Login redirecting in cakePHP 3.4

ε祈祈猫儿з 提交于 2019-12-08 03:23:53
问题 I'm trying to redirect to current page after logged in, using cakephp 3.4 but I'm getting like this localhost page isn't working, locahost page redirecting you too many times. Try clearing your cookies for 2 sec after that it's redirecting to home page. Please help me out here. Here my code In appController.php public function initialize() { parent::initialize(); $this->loadComponent('RequestHandler'); $this->loadComponent('Flash'); $this->loadComponent('Auth', [ 'authorize' => ['Controller']

CakePHP 3: CounterCache with BelongsToMany

感情迁移 提交于 2019-12-08 02:35:56
问题 I have a BelongsToMany association, my tables are PostsTable , TagsTable and PostsTagsTable . As explained here in the CakePHP book (associations), I have this fields: tags.id, tags.tag, tags.post_count posts_tags.id, posts_tags.tag_id, posts_tags.post_id Everything works correctly for now. So, as you can understand, now I want to use the tags.post_count field with CounterCache . I followed the CakePHP book, but I suppose this is a special case, in fact it doesn't work by simply adding the

CakePHP 3: CounterCache with BelongsToMany

自作多情 提交于 2019-12-06 11:52:17
I have a BelongsToMany association, my tables are PostsTable , TagsTable and PostsTagsTable . As explained here in the CakePHP book (associations) , I have this fields: tags.id, tags.tag, tags.post_count posts_tags.id, posts_tags.tag_id, posts_tags.post_id Everything works correctly for now. So, as you can understand, now I want to use the tags.post_count field with CounterCache . I followed the CakePHP book , but I suppose this is a special case, in fact it doesn't work by simply adding the behavior to the PostsTable . Can you help me? Thanks. From CakePHP Book The CounterCache behavior works