I wish the documentation for the Auth had at least one full code example of how it should be used, because it is difficult for newbies to grasp right now.
I have this code, which does not work:
<?php
class AdminController extends Controller {
function beforeroute() {
// render header
echo \Template::instance()->render('adminheader.html');
}
function login($f3) {
$auth->reset();
$user = new Users($this->db);
$auth = new \Auth($user, array('id'=>'username', 'pw'=>'password'));
$auth->basic();
if (!$auth->dry()) {
$f3->set('SESSION.username', $auth->id);
}
else $f3->reroute('/');
}
function render($f3){
$quizzes = new Quizzes($this->db);
$quiz = $quizzes->all();
$topicCount = $quizzes->topicCount();
$f3->set('quiz',$quiz);
$f3->set('topicCount',$topicCount);
if ($f3->get('SESSION.username')=='admin')
echo \Template::instance()->render('admin.html');
else $this->login($f3);
}
}
I'm not sure what I'm doing wrong, but it gives me this error: Internal Server Error Fatal error: Call to a member function reset() on null [app/controllers/AdminController.php:12]
Any help would be appreciated. Also, if somebody could just add a code example of how to use Auth() to the documentation, that would be fantastic and would prevent a lot of silly questions like this one! I noticed a lot of similar questions on this forum about this module asking for examples.