It's not finished yet, but I want to know if the structure and the classes are ok and what can I change. Feel free to say anything.
To be more specific, I want to know what you think about the login function in the Login_Controller
class:
public function login() {
if (!empty($_POST['username']) && !empty($_POST['password'])) {
$user = new Users_Model;
$username = $_POST['username'];
$password = $_POST['password'];
if ($iduser = $user->is_registered($username, $password)) {
$_SESSION['user'] = $username;
$_SESSION['iduser'] = $iduser;
if ($_POST['keep']) {
$user->save_cookie($username);
}
header('Location: ' . SITE_ROOT);
exit();
} else {
$error = 'El usuario o el password no son correctos.';
$this->main($error);
}
} else {
$error = 'No ingreso el usuario o el password.';
$this->main($error);
}
}
And the router as well:
class Router {
static function init($request)
{
$parsed = explode('/', $request);
if ($parsed[0] == 'admin') {
$page = array_shift($parsed).ucfirst(array_shift($parsed));
} else {
$page = array_shift($parsed);
}
if (empty($page)) {
$page = 'index';
}
$action = array_shift($parsed);
if (empty($action)) {
$action = 'main';
}
if (empty($parsed)) {
$arguments = 0;
} else {
$arguments = $parsed;
}
$target = SERVER_ROOT . '/controllers/' . $page . '.php';
if (file_exists($target)) {
include_once $target;
$class = ucfirst($page) . '_Controller';
if (class_exists($class)) {
$controller = new $class;
} else {
die('la clase no existe');
}
} else {
die('la pagina no existe');
}
$controller->$action($arguments);
}
}