cakephp

cakephp validation from both model and controller

…衆ロ難τιáo~ 提交于 2020-01-22 20:52:06
问题 I have given validation in model. Also, I have given some validation in controller for checking the captcha code. After that, the application is not displaying the model validation errors. If I comment the controller code, model validation is working fine and displaying the errors. Both not working.. Model code (sample) class User extends AppModel { var $name = 'User'; var $validate = array( 'username' => 'notempty', 'firstname' => 'notempty' ); } Controller code if (!empty($this->data)) {

Embedding YouTube video with new iframe embed code in TinyMCE

余生长醉 提交于 2020-01-22 19:24:06
问题 I tried the old embed code for adding YouTube videos into TinyMCE and it works fine. Some of the users may not realise they have to click on the old embed code option in YouTube embed code link to add it in. I want to make it easy for users and allow them to just copy the new embed code directly and paste it on TinyMCE and away they go. The new embed code looks like the following example: <iframe title="YouTube video player" width="640" height="390" src="http://www.youtube.com/embed/VvJ037b

Sort table header in descending order page wise without sorting whole database table [duplicate]

杀马特。学长 韩版系。学妹 提交于 2020-01-22 03:45:05
问题 This question already exists : sort a data table header only in that page cakephp Closed 4 years ago . I would like to know how to sort a table header only in that page without sorting the whole table.is this possible in cakephp? please show me some sample code. my view is <?php echo $url = $this->Paginator->sort('ID', 'id',array('direction' => 'desc')); $arrow = getArrow($url); ?> This is my Controller: $this->paginate = Set::merge($this->paginate, array('OrderFinalized' => array( 'limit'=>4

Build a tree menu with li tag from array

限于喜欢 提交于 2020-01-22 02:40:11
问题 I am retrieving an array and I made function to structure the array so it looks tree array. How to make tree menu with list tag (ul, li) function buildTree(array &$elements, $parentId = 0, $elkey = null) { $branch = array(); foreach ($elements as $key=>$element) { if ($element[$elkey]['parent_id'] == $parentId) { $children = buildTree($elements, $element[$elkey]['id'], $elkey); if ($children) { $element['children'] = $children; } $branch[$element[$elkey]['id']] = $element; unset($elements[

Problems inserting data in Cakephp

谁都会走 提交于 2020-01-22 02:22:07
问题 In the database after the execution of the add method I retrieve only the foreign key tarid_id the other fields are empty here is my code of the Adherent Model: Thanks for the answer <?php App::uses('AppModel', 'Model'); /** * Adherant Model * * @property User $User * @property Tarif $Tarif */ class Adherant extends AppModel { /** * Validation rules * * @var array */ public $validate = array( 'nom' => array( 'notempty' => array( 'rule' => array('notempty'), //'message' => 'Your custom message

autoComplete CakePHP 2.0

泄露秘密 提交于 2020-01-22 00:55:30
问题 Since CakePHP 1.3, the Ajax helper has been deprecated, one cannot user $ajax->Autocomplete.. I use Cake 2.0, and wish to implement dynamic autocomplete( dynamic table, dynamic field) it seems impossible with current tutorials available. What is closest alternative to $ajax->autoComplete in cakephp 2.0? 回答1: One method I've used is to create an Autocomplete Controller (or better yet build it as a plugin), with a method similar to this: class AutocompleteController extends AppController {

cakephp form validation

↘锁芯ラ 提交于 2020-01-21 05:45:08
问题 does anyone know if there is a VALIDATE function for a form in cakePHP and view the errors array? i.ve checked the documentation but the only thing i found is the SAVE function, i just need to know if the data i send is valid and review the errors manually. 回答1: Try this $this->ModelName->set( $this->data ); if ($this->ModelName->validates()) { // it validated logic } else { // didn't validate logic } And read this 来源: https://stackoverflow.com/questions/3343472/cakephp-form-validation

CakePHP: Use post title as the slug for view method

戏子无情 提交于 2020-01-20 09:01:32
问题 I have been trying to do the following method to create urls like: domain.com/portfolio/This_is_a_test_post function view ( $title ) { $post = $this->Portfolio->find('first', array('conditions' => array(Inflector::slug('Portfolio.title') => $title))); //$posts = $this->Portfolio->title = Inflector::slug($title); if (empty($title)) { $this->cakeError('error404'); } else { $this->set(compact('post')); } } However it doesn't show the post! Obviously I'm doing something wrong... Any ideas on how

how using SQL IN operator in find method of cakephp ORM

六眼飞鱼酱① 提交于 2020-01-20 04:02:28
问题 i am beginner in cakephp , and i want use SQL IN operator in find method , i have words table. my code is : $this->Word->find('Word.wordid in (83,82)'); , and this code create this query : SELECT `Userword`.`userwordid`, `Userword`.`userid`, `Userword`.`wordid`, `Userword`.`date`, `Userword`.`levelid` FROM `userwords` AS `Userword` WHERE `Userword`.`wordid` = (82) but i need this query SELECT `Userword`.`userwordid`, `Userword`.`userid`, `Userword`.`wordid`, Userword`.`date`, `Userword`.

Attach multiple files to email in CakePHP

不想你离开。 提交于 2020-01-17 18:09:10
问题 I want to attach 5 dynamic text file in mail but not working. I send single attachment in email working perfect my code is : $Email->attachments('path/to/example.txt'); But i send multiple attachment in email not working. My code is : $Email->attachments('path/to/example.txt','path/to/example1.txt','path/to/example3.txt','abs/path/to/example4.txt','path/to/example5.txt'); 回答1: Try this code for multiple attachment : $Email->attachments(array( 'example.txt' => array( 'file' => 'path/to/example