Pages

Thursday, July 30, 2015

Cakephp 2.0-Validations not working

Many a times Our custom Validations do not work in cakephp due to very tiny small errors.Here is a piece of my research and development which might help you
 In the controller
       if (!empty($this->data))   
       {  
         $this->User->set($this->data);  
         if ($this->User->validates())   
         {  
           // it validated logic  
           echo "Yes we can proceed";  
         }   
         else   
         {  
           // didn't validate logic  
           $errors = $this->User->validationErrors;  
           pr($errors);  
         }  
       }  

See the line in Bold this must be done to get errors set

In the view
   <?php   
       if($this->Form->isFieldError('User.username'))  
       {  
         echo $this->Form->error('User.username', null, array('class' => 'message'));   
       }  
       ?>  
Now set the class to taste and you will get error message in view in desired color.

Thursday, July 9, 2015

Cakephp 2.0-Adding favicon to your website

I was able to add a favicon to my website using code mentioned.This one is trusted and working.

 echo $this->Html->meta('favicon.ico','img/favicon.ico',array('type' => 'icon'));  

You need to place your favicon.ico file in/webroot/img directory