0
votes

I want to create an "Admin Panel/Interface" in one of my CakePHP projects. You know its very common in modern web sites. At first, I planned to create a plugin for this, and tried to do it. It didn't work, no idea why, I'll ask for help for it later. But, next I saw that CakePHP already provides this feature, using "Scafolding". I am now trying this, but don't know why its not working as I expected. Here is what I did :

app/config/core.php :
---------------------
.
.
.
Configure::write('Routing.prefixes',array('admin'));
.
.
.

app/Controller/AppController.php :
----------------------------------
.
.
.
public $components=array(
    'Session',
    'Auth'=>array(
        'loginRedirect'=>array('admin'=>true,'controller'=>'home','action'=>'index'),
        'logoutRedirect'=>array('controller'=>'home','action'=>'index'),
        'authorize'=>array('Controller')
    )
);
.
.
.

I thought, there should be a seperate controller for Admin Panel, that's why I created it :

app/Controller/AdminsController.php :
-------------------------------------
<?php
    App::uses('AppController','Controller');
    class AdminsController extends AppController{
       public $name='Admins';
       public $scaffold='admin';
    }

But it didn't work. So, I thought CakePHP provided this feature for all individual controller; I mean, I thought I am supposed to have the Admin Panel for all individual controller, not as a different module/controller/sub-system. So, I changed a little one of my existing controllers "Controllers1" :

<?php
    App::uses('AppController','Controller');
    class Controllers1Controller extends AppController{
       public $name='Controllers1';
       public $scaffold='admin';
    }

then tried to go to this URL : my_site/admin/jobs/view but still same result.

Please give me a suggestion, what should I do ? Should I create a new plugin for the "Admin Panel", or Scafolding is better ? And what is my fault ?

Thanks

1

1 Answers

1
votes

The AdminsController is not necessary to use the admin prefix, all you need to do is define the Routing.Prefixes like you already did.

Configure::write('Routing.prefixes',array('admin'));

For the JobsController example that you mentioned to us what all you need to do to make it work is:

<?php

App::uses('AppController', 'Controller');

class JobsController extends AppController {
     public $scaffold = 'admin';
}

Because the way to make Routing Prefixes work is to declare methods with the prefixes, not use an additional controller:

<?php


App::uses('AppController', 'Controller');

class ArticlesController extends AppController {

      function admin_index() {
        //This method can be found under /admin/articles
      }
}