Senin, 09 Desember 2013

CARA MEMBUAT CONSOLE DI CAKEPHP




1.       C:\xampp\php

2   C:\xampp\htdocs\cakephp\app\Console

3. C:\Program Files\PC Connectivity Solution\;%SystemRoot%\system32;%SystemRoot%;%SystemRoot%\System32\Wbem;%SYSTEMROOT%\System32\WindowsPowerShell\v1.0\;c:\Program Files\Common Files\Ulead Systems\MPEG;C:\xampp\php;C:\xampp\htdocs\alaxos\app\Console;C:\Program Files\Bitvise

3
 
Read More

SIMPLE AUTH CAKE 2.20


     
Cara membuat simple auth sederhana

Cara membuat simple auth sederhana
1. Tambahkan public komponen
public $components = array(
'Session',
'Auth' => array(
'loginRedirect' => array('controller' => 'posts', 'action' => 'index'),
'logoutRedirect' => array('controller' => 'pages', 'action' => 'display','home')));

public function beforeFilter(){
$this->Auth->allow('*');
}





2. Di user controller tambahkan kode public function login() and Logout ()
public function beforeFilter() {
    parent::beforeFilter();
    $this->Auth->allow(''); // Letting users register themselves
}
public function login(){
    $this->layout='loginadmin';
if ($this->request->is('post')){
if ($this->Auth->login()){
$this->redirect($this->Auth->redirect('users/index'));
} else {
$this->Session->setFlash(__('Invalidusernameorpassword,tryagain'));
}
}
}
public function logout(){
$this->redirect($this->Auth->logout());
}



3.    Kemudian pada table user model script dibawah ini
                public $validate = array(
                                'username' => array(
                                                'notempty' => array(
                                                                'rule' => array('notempty'),
                                                                //'message' => 'Your custom message here',
                                                                //'allowEmpty' => false,
                                                                //'required' => false,
                                                                //'last' => false, // Stop validation after this rule
                                                                //'on' => 'create', // Limit validation to 'create' or 'update' operations
                                                ),
                                ),
                                'password' => array(
                                                'notempty' => array(
                                                                'rule' => array('notempty'),
                                                                //'message' => 'Your custom message here',
                                                                //'allowEmpty' => false,
                                                                //'required' => false,
                                                                //'last' => false, // Stop validation after this rule
                                                                //'on' => 'create', // Limit validation to 'create' or 'update' operations
                                                ),
                                ),
                                'role' => array(
                                                'notempty' => array(
                                                                'rule' => array('notempty'),
                                                                //'message' => 'Your custom message here',
                                                                //'allowEmpty' => false,
                                                                //'required' => false,
                                                                //'last' => false, // Stop validation after this rule
                                                                //'on' => 'create', // Limit validation to 'create' or 'update' operations
                                                ),
                                ),
                );

//app/Model/User.php
//App::uses(’AuthComponent’, ’Controller/Component’);
//class User extends AppModel{
////...
public function beforeSave($options = array()) {
if (isset($this->data[$this->alias]['password'])){
$this->data[$this->alias]['password'] = AuthComponent::password($this->data[$this->alias]['password']);
}
return true;
}

4.  Untuk database users dengan format seperti di bawah ini

5.   Untuk controller lain2nya silahkan tambahkan before filter function login N logout seperti langkah yang ke 3.
Semoga berhasil.. ini catatan 





























 

Read More
Powered By Blogger · Designed By asadly.tk