Good morning, I have a problem, the administrator user thinks, but the page does not work for me, here are the codes:
These codes are copied from the cake book 2.x
If I do this, it goes well:
App::uses('Controller', 'Controller');
class AppController extends Controller {
public $components = array(
'Session' ,
'Auth' => array(
'loginRedirect' => array('controller' => 'users', 'action' => 'index'),
'logoutRedirect' => array('controller' => 'users', 'action' => 'login')
)
);
public function beforeFilter() {
$this->Auth->allow('index', 'view');
}
}
The thing is that I'm asking for it from the main page and that's not what I want, if my main page is Index , I want it ask at Idex / Admin
These are the codes that I have UsersController
<?php
// app/Controller/UsersController.php
App::uses('AppController', 'Controller');
class UsersController extends AppController {
// app/Controller/UsersController.php
public function beforeFilter() {
parent::beforeFilter();
// Allow users to register and logout.
$this->Auth->autoRedirect = false;
}
public function login() {
if ($this->request->is('post')) {
if ($this->Auth->login()) {
return $this->redirect($this->Auth->redirectUrl());
} else {
$this->Session->setFlash(__('Invalid username or password, try again'));
}
}
}
public function logout() {
return $this->redirect($this->Auth->logout());
}
public function index() {
$this->User->recursive = 0;
$this->set('users', $this->paginate());
}
public function view($id = null) {
$this->User->id = $id;
if (!$this->User->exists()) {
throw new NotFoundException(__('Invalid user'));
}
$this->set('user', $this->User->findById($id));
}
public function add() {
if ($this->request->is('post')) {
$this->User->create();
if ($this->User->save($this->request->data)) {
$this->Session->setFlash(__('The user has been saved'));
return $this->redirect(array('action' => 'index'));
}
$this->Session->setFlash(
__('The user could not be saved. Please, try again.')
);
}
}
public function edit($id = null) {
$this->User->id = $id;
if (!$this->User->exists()) {
throw new NotFoundException(__('Invalid user'));
}
if ($this->request->is('post') || $this->request->is('put')) {
if ($this->User->save($this->request->data)) {
$this->Session->setFlash(__('The user has been saved'));
return $this->redirect(array('action' => 'index'));
}
$this->Session->setFlash(
__('The user could not be saved. Please, try again.')
);
} else {
$this->request->data = $this->User->findById($id);
unset($this->request->data['User']['password']);
}
}
public function delete($id = null) {
// Prior to 2.5 use
// $this->request->onlyAllow('post');
$this->request->allowMethod('post');
$this->User->id = $id;
if (!$this->User->exists()) {
throw new NotFoundException(__('Invalid user'));
}
if ($this->User->delete()) {
$this->Session->setFlash(__('User deleted'));
return $this->redirect(array('action' => 'index'));
}
$this->Session->setFlash(__('User was not deleted'));
return $this->redirect(array('action' => 'index'));
}
}
User model
<?php
App::uses('AppModel', 'Model');
class User extends AppModel {
public $validate = array(
'id' => array(
'rule' => 'notBlank'
),
'user' => array(
'required' => array(
'rule' => 'notBlank',
'message' => 'A username is required'
)
),
'key' => array(
'required' => array(
'rule' => 'notBlank',
'message' => 'A password is required'
)
),
'rol' => array(
'valid' => array(
'rule' => array('inList', array('admin', 'author')),
'message' => 'Please enter a valid role',
'allowEmpty' => false
)
),
'created' => array(
'rule' => 'notBlank'
)
);
}
Login view
//app/View/Users/login.ctp
<div class="users form">
<?php echo $this->Session->flash('auth'); ?>
<?php echo $this->Form->create('User'); ?>
<fieldset>
<legend>
<?php echo __('Please enter your username and password'); ?>
</legend>
<?php echo $this->Form->input('username');
echo $this->Form->input('password');
?>
</fieldset>
<?php echo $this->Form->end(__('Login')); ?>
</div>
I even enrute to see if with that I did what I mentioned in www ... / admin but that does not do it is anda.
Router::connect('/admin', array('controller' => 'Users', 'action' => 'display', 'Users/login'));
that's how it works, but if you document AppController staying like this:
App::uses('Controller', 'Controller');
class AppController extends Controller {
// public $components = array(
// 'Session' ,
// 'Auth' => array(
// 'loginRedirect' => array('controller' => 'users', 'action' => 'index'),
// 'logoutRedirect' => array('controller' => 'users', 'action' => 'login')
// )
// );
//
// public function beforeFilter() {
// $this->Auth->allow('index', 'view');
// }
}
Ps comes out this:
Ps this is the index as it should be, now if I go to www ... / admin
Now siven in admin pulls that out, and even though it pulls errors I get the layout default and I want to change it or at least not show me the menu (stripes on the right side) ps that menu is only for new clients