cakephp-2.x

CakePHP 2.x GROUP BY within Containable

Deadly 提交于 2019-12-07 14:58:59
问题 I am going nuts trying to find a good solution, either using the set::extract() or something. I want to add a GROUP BY within my containable: $params = array( 'conditions'=>array( 'Project.id'=>$ProjectId ), 'contain'=>array( //Gets the User Who owns the Project 'User'=>$user, 'Bid'=>array( //The User Who owns the Bid 'User'=>$user ), 'ProjectType', 'Os', 'Comment'=>array( 'To'=>$user, 'From'=>$user, 'group'=>"Comment.from_id" ), ), ); //debug($params); return $this->find('first',$params); I

CakePHP - Where is the best place to put custom utility classes in my app structure?

别说谁变了你拦得住时间么 提交于 2019-12-07 13:31:01
问题 I am making utility classes that will provide general methods for helping manipulate strings. I may also want one for arrays, math functions, etc. Should these be components? Vendors? Could I maybe make these into some sort of vendor package? 回答1: If they're general standalone libraries not tied to any particular step of the request cycle (controller, model, view), put them in app/libs/ . You can import them using App::import('Lib', 'Foo') . Personally I have two or three handy array

CakePHP - Where is the best place to put custom utility classes in my app structure?

风流意气都作罢 提交于 2019-12-05 18:40:44
I am making utility classes that will provide general methods for helping manipulate strings. I may also want one for arrays, math functions, etc. Should these be components? Vendors? Could I maybe make these into some sort of vendor package? If they're general standalone libraries not tied to any particular step of the request cycle (controller, model, view), put them in app/libs/ . You can import them using App::import('Lib', 'Foo') . Personally I have two or three handy array functions I always use defined in bootstrap.php , which is another place to put a small amount of global stuff. 来源:

CakePHP 2.x GROUP BY within Containable

不问归期 提交于 2019-12-05 18:34:34
I am going nuts trying to find a good solution, either using the set::extract() or something. I want to add a GROUP BY within my containable: $params = array( 'conditions'=>array( 'Project.id'=>$ProjectId ), 'contain'=>array( //Gets the User Who owns the Project 'User'=>$user, 'Bid'=>array( //The User Who owns the Bid 'User'=>$user ), 'ProjectType', 'Os', 'Comment'=>array( 'To'=>$user, 'From'=>$user, 'group'=>"Comment.from_id" ), ), ); //debug($params); return $this->find('first',$params); I do not want to hack to get around this issue - is there an easier way to do this? For anyone else that

Get original associations after using Containable behavior in CakePHP

江枫思渺然 提交于 2019-12-04 06:22:26
问题 Background: CakePHP 2.6.3. A pretty stable app. New behavior ( MyCustomBehavior ) created to output some extra info. I have a Model MyModel acting as Containable (defined in AppModel ) and then MyCustom (defined in MyModel ). MyCustomBehavior is written in a way that it needs to work with the Model's associations with other Models in my app. Problem: Whenever I contain related models in my find() call of MyModel , I cannot get a complete list of MyModel associations because Containable

CakePHP: How can I use a “HAVING” operation when building queries with find method?

我只是一个虾纸丫 提交于 2019-12-02 22:29:10
I'm trying to use the "HAVING" clause in a SQL query using the CakePHP paginate() method. After some searching around it looks like this can't be achieved through Cake's paginate()/find() methods. The code I have looks something like this: $this->paginate = array( 'fields' => $fields, 'conditions' => $conditions, 'recursive' => 1, 'limit' => 10, 'order' => $order, 'group' => 'Venue.id'); One of the $fields is an alias "distance". I want to add a query for when distance < 25 (e.g. HAVING distance < 25). I have seen two workarounds so far, unfortunately neither suit my needs. The two I've seen

Decrypt and Encrypt using CallBack Methods in cakephp

冷暖自知 提交于 2019-12-02 00:06:51
I want to use the Callbacks methods to encrypt a value before it gets stored in my database and decrypt it before showing it back in the application. I used one of the examples provided in the documentation . In my core.php I put the following : Configure::write('Security.cipherCriptKey','su0HKssPmdbwgK6LdQLqzp0YmyaTI7zO'); In my Model, I used two methods: beforeSave() public function beforeSave($options = array()) { $value=$this->data['Internship']['encryptedindb']; $encrypted = Security::encrypt($value, Configure::read('Security.cipherCriptKey')); $this->data['Internship']['encryptedindb'] =

CakePHP select default value in SELECT input

时间秒杀一切 提交于 2019-11-30 08:26:52
Using CakePHP: I have a many-to-one relationship, let's pretend it's many Leafs to Trees. Of course, I baked a form to add a Leaf to a Tree, and you can specify which Tree it is with a drop-down box ( tag) created by the form helper. The only thing is, the SELECT box always defaults to Tree #1, but I would like it to default to the Tree it's being added to: For example, calling example.com/leaf/add/5 would bring up the interface to add a new Leaf to Tree #5. The dropdown box for Leaf.tree_id would default to "Tree 5", instead of "Tree 1" that it currently defaults to. What do I need to put in

CakePHP select default value in SELECT input

旧时模样 提交于 2019-11-29 11:34:11
问题 Using CakePHP: I have a many-to-one relationship, let's pretend it's many Leafs to Trees. Of course, I baked a form to add a Leaf to a Tree, and you can specify which Tree it is with a drop-down box ( tag) created by the form helper. The only thing is, the SELECT box always defaults to Tree #1, but I would like it to default to the Tree it's being added to: For example, calling example.com/leaf/add/5 would bring up the interface to add a new Leaf to Tree #5. The dropdown box for Leaf.tree_id

cakephp 2 ajax form

可紊 提交于 2019-11-29 11:25:08
I'm having trouble building an ajax form in cakephp 2 which obviously has changed a lot since 1.3. I'm using the following code: <div id="commentForm"> <div id="commentStatus"></div> <?php echo $this->Form->create('Comment', array('action' => 'save', 'default' => false)); echo $this->Form->input('Comment.comments_name'); echo $this->Form->input('Comment.comments_email'); echo $this->Form->input('Comment.comments_text'); echo $this->Js->submit('Save', array('update' => '#commentStatus')); echo $this->Form->end(); ?> However the form is not submitted when pressing the button. I will be thankful