We’ve decided to use CakePHP for a login system and frontend database UI because of all the automagic when adhering to its strict conventions, I know Codeigniter and with CI you can extend the system controller in system/core/Controller.php to handle authentication
class AdminController extends CI_Controller {
protected $user;
public function __construct() {
parent::__construct();
$this->load->model('AdminModel');
$this->user = $this->AdminModel->user()->row();
$data->user = $this->user;
$this->load->vars($data);
}
}
Then by extending it as an application controller, $user becomes available globally and the AdminController already extends CI_Controller.
class Admin extends AdminController {
public function __construct() {
parent::__construct();
}
function index(){
//$user is global since it's extending AdminController
$this->data['user'] = $user->someItem;
//load view etc..
}
}
I’m not sure if this is the correct approach with CakePHP, is there a general consensus/best practice for scallable login systems that impliment automagic?
Thanks in advance
You can just use
AuthComponent::user()where ever you need the details, orAuthComponent::user('id')where you need a specific field.