cakephp-2.0

Find where id is not in array of ids

半世苍凉 提交于 2019-12-03 10:51:23
To find id whose value is equal to the id of an array of ids: $this->YourModel->find('all', array( 'conditions' => array( "YourModel.id" => array(1, 2, 3, 4) ) )); How I can do the opposite, find elements where the ids are different than an array of ids? This should work: $this->YourModel->find('all', array( 'conditions' => array( "NOT" => array( "YourModel.id" => array(1, 2, 3, 4) ) ) )); http://book.cakephp.org/2.0/en/models/retrieving-your-data.html#complex-find-conditions 来源: https://stackoverflow.com/questions/14508682/find-where-id-is-not-in-array-of-ids

CakePHP: How to update multiple records at the same time with the Form helper

笑着哭i 提交于 2019-12-03 08:39:42
On an edit page for the model Test I want to be able to update the "Questions.order" field on all of it's associated (by hasMany) questions from the same form. I've ready the Cake book chapter on saveMany()/saveAll() in the book, and I'm using the Model.0.field syntax but I can't figure out how to tell CakePHP which record to corresponds to which input. Should the # in Model.#.field correspond to the question's id field? Here's what I'm currently doing: echo $this->Form->create( 'Question', array('action'=>'order')); $n = 0; foreach ($questions_array as $question) : ?> <?php echo $this->Form-

CakePHP 2: new exceptions

戏子无情 提交于 2019-12-03 07:32:40
I'd like to create a new exception, called SecurityException. Where should I put the code? class SecurityException extends CakeException {}; Thanks! Create an exceptions.php file, put it on the Lib folder and fill it up with all your *Exception classes. Then include it on your application's bootstrap file. require APP . 'Lib' . DS . 'exceptions.php'; All exceptions will become available application wide. I followed luchomolina's 2nd answer (commented on his own answer), and thought it deserved to be an official answer: Here's another approach: "put exceptions in ([plugin-if-any])/Lib/Error

In View(CakePHP), the proper way to get current controller?

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-03 07:27:44
问题 In View, I can get action by using $this->action But, I cannot get controller name by $this->controller What is the proper way to get current controller in View? 回答1: Use $this->params['controller'] to get the current controller. You can do a debug($this->params) to see other available variables. 回答2: You can get controller like this: echo "<pre>controller:".$this->request->params['controller']."</pre>"; Although $this->params is shorter, $this->request->params is more autocomplete friendly.

Cakephp Upgrade from 1.3 to 2.1

我是研究僧i 提交于 2019-12-03 06:25:39
问题 UPDATE: the question i asked doesn't quite cover how deep i went in doing this upgrade! If you stumble on this, i hope the answer i pushed is useful to you So, in an effort to get the "forum" plugin working, i've decided to upgrade cakephp from 1.3 to 2.1 (This was because the forum plugin uses something called CakeDC utils, and they are already up to cakephp 2.0, and surprise surprise, the 2.3 version of forum isn't clear which utils it works with...) Ok, so I have run the cake upgrader

CakePHP 2.0 Determine which submit button has been clicked

北战南征 提交于 2019-12-03 06:24:23
In CakePHP 1.3 you can create a form with multiple submit buttons: echo $this->Form->submit('Submit 1', array('name'=>'submit'); echo $this->Form->submit('Submit 2', array('name'=>'submit'); and detect which submit button was pressed in the controller with: if (isset($this->params['form']['submit']) && $this->params['form']['submit'] == "Submit 1") { // first button clicked } In CakePHP, $this->params['form'] isn't set and the clicked button value doesn't appear anywhere in $this->request, $this->request->data, $this->params, $this->data or $_POST . How do I determine which button has been

Lots of Login Code

十年热恋 提交于 2019-12-02 22:00:21
问题 This is a fairly long question but I have know idea where it's going wrong. I am making an ajax login script using CakePHP 2.0 but it keeps failing. I will post all of my code, and i hope someone has the time to go through it. This is my sql Database AccountID AccountEmail AccountPassword AccountActive 1 chris@hotmail.co.uk pass 0 2 chris@gmail.com pass 1 This is my relevant Model Code class Account extends AppModel { public $name = 'Account'; public $validate = array( 'AccountEmail' => array

In View(CakePHP), the proper way to get current controller?

孤人 提交于 2019-12-02 20:09:51
In View, I can get action by using $this->action But, I cannot get controller name by $this->controller What is the proper way to get current controller in View? Wa0x6e Use $this->params['controller'] to get the current controller. You can do a debug($this->params) to see other available variables. trante You can get controller like this: echo "<pre>controller:".$this->request->params['controller']."</pre>"; Although $this->params is shorter, $this->request->params is more autocomplete friendly. You can check the autocomplete options from this question: PHPStorm autocomplete for CakePHP custom

Cakephp Upgrade from 1.3 to 2.1

Deadly 提交于 2019-12-02 19:48:18
UPDATE: the question i asked doesn't quite cover how deep i went in doing this upgrade! If you stumble on this, i hope the answer i pushed is useful to you So, in an effort to get the "forum" plugin working, i've decided to upgrade cakephp from 1.3 to 2.1 (This was because the forum plugin uses something called CakeDC utils, and they are already up to cakephp 2.0, and surprise surprise, the 2.3 version of forum isn't clear which utils it works with...) Ok, so I have run the cake upgrader magic thing, in accordance with the instructions found here: http://book.cakephp.org/2.0/en/console-and

CakePHP- cakeDC search plugin implementation

萝らか妹 提交于 2019-12-02 19:08:18
问题 I am currently trying to figure out a way to implement cakeDC's search plugin within my application, but I am finding it quite difficult to understand the plumbing that needs to be done before I can get it to work(nicely) with my app. Things to consider: the search needs to be a 'live search' Records retrieved need to be paginated The search will be done using a selected criteria (id,name,etc the actual key not value) and will require a user entry which we will call 'query' for now.. here is