Thursday, December 4, 2014

Re: In CakePHP 3, how do I bake admin controller?

In your config/routes.php add this:

Router::prefix('admin', function ($routes) {
    $routes
->fallbacks();
});

In AppController.php:
class AppController extends Controller {
   
public function initialize() {
        $this
->loadComponent('Auth')
   
}
   
public function beforeFilter(Event $event) {
       
if ($this->request->prefix === null) {
            $this
->Auth->allow();
       
}
   
}
   
public function isAuthorized($user) {
       
if ($this->request->prefix === 'admin') {
           
return (bool)$user['role'] === 'admin';
       
}
   
}
}

In src/Controller/Admin/UsersController.php
namespace App\Controller\Admin;
use App\Controller\AppController;
class UsersController extends AppController {
   
public function index() {
        $users
= $this->paginate();
        $this
->set(compact('users'));
   
}
}

Put the view template in src/Template/Admin/Users/index.ctp

--cesar



El miércoles, 3 de diciembre de 2014 13:55:20 UTC-2, frocco escribió:
I want to create admin controller with view

Thanks

--
Like Us on FaceBook https://www.facebook.com/CakePHP
Find us on Twitter http://twitter.com/CakePHP

---
You received this message because you are subscribed to the Google Groups "CakePHP" group.
To unsubscribe from this group and stop receiving emails from it, send an email to cake-php+unsubscribe@googlegroups.com.
To post to this group, send email to cake-php@googlegroups.com.
Visit this group at http://groups.google.com/group/cake-php.
For more options, visit https://groups.google.com/d/optout.

No comments: