cakephp-1.3

cakephp validation and regular expressions

谁说胖子不能爱 提交于 2019-12-10 17:14:02
问题 I am working in cakephp1.3. i have to validate my form using cakephp validation in model.i added a regular expression to restrict special characters entry. My code is written below: var $validate = array( 'name' => array( 'unique'=>array( 'rule' => 'isUnique', 'message' => 'Already taken', ), 'pattern'=>array( 'rule' => '/^[a-z]$/i', 'message' => 'Only letters allowed', ), 'empty'=>array( 'rule' => 'notEmpty', 'message' => 'This field cannot be left blank', )) ); rule 'unique' is not working.

Calling function in view of cakephp

喜欢而已 提交于 2019-12-10 10:38:10
问题 I have one team array and want that team name every where to show team name.It is possible to built a global function which can return team name and I call that function from my view means ctp file. 回答1: please try this for west: <?php // controller name like app,users // action name like getdata should be in controller // and you can send parameter also $output = $this->requestAction('controllerName/actionName/'.$parameter); ?> 回答2: There are multiple approaches to this. What I cannot tell

CakePHP 1.3: Measuring Page Execution Time

社会主义新天地 提交于 2019-12-10 10:29:29
问题 Looking to figure out how to measure the total PHP execution time of a CakePHP site. It looks like in 1.2 this was included in the rendered HTML as a HTML comment when in debug mode, but this is not happening on my 1.3 site, and in any case I want it as an element I can output to the user, not a comment. I can do this easily in regular PHP using microtime() but I'm not sure where to add the code in CakePHP, and I suspect it might have a more robust execution timer anyway. Ideas? 回答1: Just in

CakePHP preserving validation errors after redirecting

守給你的承諾、 提交于 2019-12-10 09:45:39
问题 I have an element which displays a comment form, the action is comments/add. If the form doesn't validate, I don't want users to go to comments/add (the view for which does not exist), but I want them to remain on the same page and see the validation errors there. However, redirecting to $this->referer() doesn't work - the validation errors disappear and just the flash message remains. public function add(){ if (!empty($this->data)){ $this->Comment->create(); if ($this->Comment->save($this-

CakePHP - query returns empty field if it has a special character in it

允我心安 提交于 2019-12-10 04:22:39
问题 I have what I think to be a normal query-call in CakePHP - it works for all results, but when a field has a special character in it, the field will return empty. It doesn't break - and it still gives me the rest of the fields - it's just that one field that's empty. Example: $this->paginate = array( 'conditions' => array( 'Item.name != ' => '', ), ); $data = $this->paginate('Item'); This will return all the items in my table (including the one that I thought had an empty name field) - but

can CakePHP automatically create tables from models?

你离开我真会死。 提交于 2019-12-09 18:45:39
问题 In python::Pylons i'm able to issue a setup-app command and it will look at my Models and issue the appropriate CREATE TABLE or CREATE INDEX ddl for my particular database. it seems like this would be a feature in CakePHP, but i'm having trouble finding it. in fact i see this in the manual: "You can create your database tables as you normally would. When you create your Model classes, they'll automatically map to the tables that you've created." which leads me to believe it doesn't exist? 回答1

How can I set the title_for_layout in the default PagesController?

廉价感情. 提交于 2019-12-09 18:29:52
问题 I cannot set title_for_layout in the PagesController that comes by default with CakePHP 1.3. I am using the following code in the display function: $this->set('title_for_layout','some title'); What am I doing wrong? 回答1: In your controller, the corresponding value is $this->pageTitle . UPDATE Oops, as noted in the comments, this is the 1.2 solution. 1.3 possibilities (after doing some research) include: Ensuring that $title_for_layout is being echoed in the layout Placing the $this->set()

FULL TEXT SEARCH in cakephp ? any example

北城余情 提交于 2019-12-09 11:20:49
问题 I am using ordinary search functionality in my business controller . but now need to implement FULL TEXT SEARCH with paginate can any one give idea or sample ? I am using MySQL with MyISAM tabes and this my table structure, fields marked bold are need to use in search CREATE TABLE IF NOT EXISTS businesses ( id bigint(20) unsigned NOT NULL AUTO_INCREMENT, created date NOT NULL, modified datetime NOT NULL, user_id bigint(20) NOT NULL, slug varchar(255) NOT NULL, **`name` varchar(255) NOT NULL,*

Applying form errors manually

余生长醉 提交于 2019-12-08 13:15:15
问题 I have a situation where I'm editing a snippet of data within a larger context. The user submits this data to a specialized action for handling and redirects back to the parent page. Because it's a redirection, validation errors aren't getting automagically set, so I'm trying to work around that. In the event of an error, I'm writing a validation_errors key to the session with a value of $model->validationErrors . In the form, though, I'd like to tell Cake to set each error so I can leverage

Validation for “at least one phone number is required” in CakePHP

给你一囗甜甜゛ 提交于 2019-12-08 04:53:15
问题 This is the model file vechile_enquiry.php <?php class VechileEnquiry extends AppModel{ var $name ='VechileEnquiry'; var $validate = array('name' => array ('rule' => 'notEmpty', 'message' => 'Please type name') ); } ?> This is the view file vechile.ctp <?php echo $this->Form->input('name', array('label'=>false)); ?> At least one phone number is required: <?php echo $this->Form->input('mobile_phone', array('label'=>false)); echo $this->Form->input('work_phone', array('label'=>false)); echo