cakephp-2.0

How to validate single field of a model in cakephp

馋奶兔 提交于 2019-12-23 18:14:52
问题 I have a model called User and its $validate has 39 field validations and working fine in UsersController. In another controller I need to use the same code and validate only a single field from controller. Can Someonce please help me with this? 回答1: Relevant docs. Use the fieldList option in the model's validates() method. $this->ModelName->set($this->data); if ($this->ModelName->validates(array('fieldList' => array('myField')))) { // If myField validated successfully... } 来源: https:/

When not to use Containable Behavior in CakePhp 2.x

不想你离开。 提交于 2019-12-23 15:29:13
问题 After a few times adding Containable Behavior to my various model classes, I have a good mind to simply chuck the line into AppModel instead and thus make every model Containable. Which then makes me wonder, is there any situation where it is not desirable or counterproductive for a particular model to have Containable Behavior? 回答1: I would say too few to be worried about. I put containable in App Model: class AppModel extends Model { public $recursive = -1; public $actsAs = array(

Testing redirections CakePHP 2.0

三世轮回 提交于 2019-12-23 13:27:06
问题 I have been looking at some examples at the cookbook but i dont get it: http://book.cakephp.org/2.0/en/development/testing.html#a-more-complex-example How can i test a redirection in a delete action like this one? public function delete($id = null){ $this->Comment->id = $id; if (!$this->Comment->exists()) { throw new NotFoundException(__('Invalid comment')); } if ($this->Comment->delete()) { $this->Session->setFlash(__('Comment deleted')); return $this->redirect(array('controller' => 'posts',

Getting 'unable to write' errors in CakePHP site

佐手、 提交于 2019-12-23 12:43:28
问题 I've a CakePHP site which is throwing errors (it was fine at first, and has been online for several months - not sure when the problem started). I'm getting: Warning (512): _cake_core_ cache was unable to write 'cake_dev_en-us' to Apc cache [CORE/Cake/Cache/Cache.php, line 310] Warning (512): _cake_core_ cache was unable to write 'cake_en-us' to Apc cache [CORE/Cake/Cache/Cache.php, line 310] Warning (512): _cake_model_ cache was unable to write 'default_projects' to Apc cache [CORE/Cake

How to choose the test DB cakePHP testing

梦想的初衷 提交于 2019-12-23 12:22:51
问题 I am using the cake bake command to create my fixture and Test models. I have done it successfully with one of my models but i am having troubles with another one. I dont know why, it tries to work with the default DB instead with the test one that i have already defined and that is the one used by the first model i tested. Both Test models, the one which works well and this 2nd one which doesn't, have been created with cake bake and they look exactly the same. Both of them have this in their

Setting headers for CakePHP Controller unit tests

烂漫一生 提交于 2019-12-23 03:44:06
问题 I'm writing some unit tests for a Controller in which the response behavior differs slightly, depending on whether $this->request->is('ajax') . I've been looking over the documentation for testing controllers, but I can't seem to find a way to simulate a request made via AJAX. Is there a way to send headers to testAction() so I can set the X-Requested-With header? Edit: You can work around this by editing the superglobals. Anyone have a less hacky solution? 回答1: One solution is to manually

CakePHP 2.x - jQuery EasyUI - how to put jQuery EasyUI in CakePHP 2.x?

人盡茶涼 提交于 2019-12-23 03:37:11
问题 I have a problem. I don't know where to put jQuery EasyUI in CakePHP? Which folder? Do I use it like a helper? Do I have to put something like: var $helpers = array('jQuery'); Do I have to put some in view? Thank you so much for your help always. :) Edit: And if you can give me some online tutorials with jQuery EasyUI with CakePHP 2.x. (I already Google it.) :D 回答1: In CakePHP javascript files are stored in app/webroot/js/. You then can include them in the layout by calling echo $html->script

How do I generate lft and rght values for a cakephp 2.0 tree?

孤者浪人 提交于 2019-12-23 02:45:09
问题 I've read that if you have a model that $actsAs = array('Tree') , that you can simply set the parent_id for your seed data, and a call to $this->Model->recover() should generate the proper lft and rght values for you, but when I do this, Cake seems to generate random values every time. The values vary from very large (in the thousands) to negative values. I've checked for circular references and found none as well. What could be wrong here? SQL: create table menus ( id int auto_increment not

Security.salt value in controller

别说谁变了你拦得住时间么 提交于 2019-12-23 01:41:36
问题 In cakephp there is one file core.php It contains Configure::write('Security.salt', 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'); How can i get the value of Security.salt in controller in cakephp. Thanks 回答1: Just try like this Configure::read('Security.salt'); it will give you the value. For more info check here 回答2: The above answers have not proven to be successful in CakePHP3. Configure::Read('Security.salt') will return a blank value. In-order to read the salt from the configuration file

CakePHP Fulltext search MySQL with rating

狂风中的少年 提交于 2019-12-22 18:36:53
问题 I've read that, to be able to rank search results you may query MySQL like this: SELECT * , MATCH (title, body) AGAINST ('$search') AS rating FROM posts WHERE MATCH (title, body) AGAINST ('$search') ORDER BY rating DESC Is there a way to do this in CakePHP 2.X? Also, I need to do this while paginating at the same time. So I think I would need to write condition for the paginator, not a direct 'query'. Thanks for your help! 回答1: Use like this it will prevent mysql injection too array("MATCH