Skip to main content

Posts

Cakephp Auth login

// Define Auth Component in AppController class AppController extends Controller { public $components = array( 'Session', 'Auth' => array( 'loginRedirect' => array( 'controller' => 'users', // Redirect URL after login action 'action' => 'index'), 'logoutRedirect' => array( 'controller' => 'users', // Redirect URL after logout action 'action' => 'login'), 'authError' =>'', 'authenticate' => array( 'Form' => array( 'fields' => array('username' => 'email') // By default Auth components takes username ) ) ) ); } // Define Login & logout function in UsersController class UsersController extends AppController { public function beforeFilter() { parent::beforeFilter(); // Allow users to register and logout. $thi...

How to make library in cakephp

1. Make a class in lib folder and Save it url_encoder.php <?php class UrlEncoder {        public static function encode($url) {                   return preg_replace(array('/\+/', '/\//'), array('-', '_'), base64_encode($url));         }  public static function decode($url_encoded) {                  return base64_decode(preg_replace(array('/-/', '/_/'), array('+', '/'), $url_encoded));         } } ?> 2. Now implement in your controller , if you want to initialize lib initially then define it in before filter function function beforeFilter() {        parent::beforeFilter();       App::import('Lib', 'UrlEncoder'); } 3. Now how to use its function UrlEncoder::encode($contact_id); UrlEncoder::decode($contact_id) ;

Cakephp Containable Behaviour

Containable Behavior This model behavior allows you to filter and limit model find operations.Containable allows you to streamline and simplify operations on your model bindings. It works by temporarily or permanently altering the associations of your models. To use the new behavior, you can add it to the $actsAs property of your model: class Post extends AppModel {     public $actsAs = array ( 'Containable' ); } You can also attach the behavior on the fly: $this -> Post -> Behaviors -> load ( 'Containable' ); You can also invoke Containable’s magic from inside the find() call: $this -> Post -> find ( 'all' , array ( 'contain' => false ));   $this -> Post -> find ( 'all' , array ( 'contain' => 'Comment.author' ));   You can also filter the associated Comment data by specifying a condition: $this -> Post -> find ( 'all' , array ( 'contain...

Model Validation in Cakephp

Server Side Model Validation in cakephp Step 1:  Create a form in in view  View  <div class="users form"> <?php echo $this->Form->create('User');?>     <fieldset>  <legend><?php echo __('Add User'); ?></legend>         <?php echo $this->Form->input('username'); echo $this->Form->input('email');  echo $this->Form->input('password'); echo $this->Form->input('password_confirm', array('label' => 'Confirm Password *', 'maxLength' => 255, 'title' => 'Confirm password', 'type'=>'password')); echo $this->Form->input('role', array( 'options' => array( 'king' => 'King', 'queen' => 'Queen', 'rook' => 'Rook', 'bishop' => 'Bishop', 'knight' => 'Knight...