CakePHP 1.3.3 Admin Section Template Files

1st September 2010 CakePHP CakePHP 1.3

I've been getting to grips with the newest release of CakePHP which at the time of writing is 1.3.3. The first thing I usually do on an application is get a simple Admin section underway and here it is.

Everything has been included in a single zip file but you must first go through the motions of creating the database and update the database.php file as well as change a few things in the core.php file.

Creating the Database

I've included the schema in the zip file but here it is for convenience:

CREATE DATABASE IF NOT EXISTS `cakephp_133`;

USE `cakephp_133`;

/*Table structure for table `cake_sessions` */
DROP TABLE IF EXISTS `cake_sessions`;
CREATE TABLE `cake_sessions` (
  `id` varchar(255) NOT NULL DEFAULT '',
  `data` text,
  `expires` int(11) DEFAULT NULL,
  PRIMARY KEY (`id`)
);

/*Table structure for table `users` */
DROP TABLE IF EXISTS `users`;
CREATE TABLE `users` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `username` varchar(255) DEFAULT NULL,
  `password` varchar(40) DEFAULT NULL,
  `last_login` datetime DEFAULT '0000-00-00 00:00:00',
  `created` datetime DEFAULT NULL,
  `modified` datetime DEFAULT NULL,
  PRIMARY KEY (`id`)
);

Updating Core files

Enter your database Username/Password into the /app/config/database.php file and change the security salt and cipherSeed variables in the /app/config/core.php file and you should be good to go.

What the template app provides

  • Register,Login,Logout functionality
  • All admin routes are protected and a user must be logged in to access them
  • Simple User management
    • View/Add/Edit/Delete/ Users

Download

I've zipped up the entire application and you can download it in a file called: cakephp-1.3.3-admin-section-template.zip. Any thoughts, comments or changes just let me know and I'll consider them.

UPDATE 22/09/10: Zip file has been updated to reflect fix from the comments. Cheers for pointing that one out!

Back to Home Page

Comments

Binh (05/09/2010 - 19:00)

It's pretty good for me as beginner in CakePHP. Thanks

Pete (09/09/2010 - 07:25)

Great article - as were the prior 2 :)
Quick comment, looks like you have forgotten to protect the admin routes in the download

James (09/09/2010 - 22:16)

@Pete: thanks for the comment although the admin route protection is taken care of in the <strong>/app/app_controller.php</strong> file, in the beforeFilter() callback.

Christian (11/09/2010 - 12:48)

Hi James...

I'm new to cakephp. So, I've been googling for over a month now, trying to find solution for almost every bit of code.
Your blog however has helped in few cases. More grease to ur elbow.

I hope to complete my admin section with this your tutorial.

But, I have one feature that have become almost imposible, which is being able to display article name as the page title, just like this your page that displays <title>CakePHP 1.3.3 Admin Section Template Files - James Fairhurst</title>

Pls help.

Thanks

James (12/09/2010 - 02:06)

@Christian: Glad that the site has helped you out. To change the page title you need to set it like this in your Controller:

$this->set('title_for_layout','PAGE TITLE GOES HERE');

Hopefully that will do the trick if you haven't modified the default layout.

Christian (12/09/2010 - 11:16)

Thanks for your quick reply.
With this solution, the page title will be static, unlike your own that changes with every article. How can such dynamic page title be achieved in cake 1.3?

Thanks

James (14/09/2010 - 11:20)

@Christian: I use my Post Title as the page title, so when viewing a Post I have something like this:

$this->set('title_for_layout',$post['Post']['title']);

Hope that helps!

Christian (15/09/2010 - 04:19)

Ok that is good. But where is the right place to place this kind of code? Assuming I want it to display different name at home page, post index page, individual pages, etc, where can I place the code and how?

James (15/09/2010 - 05:52)

@Christian: inside each Controller Action. Check out the manual for more info.

Simon (21/09/2010 - 22:34)

The line below found in app_controller:
if(isset($this->params['admin']) && $this->params['admin'] && $user === FALSE) {

should be this:
if (isset($this->params['admin']) && $this->params['admin'] && is_null($user)){

as null is not equal to false.

James (22/09/2010 - 06:53)

@Simon: You're absolutely right, will update the files when I get the chance. Good spot.

Dany (27/09/2010 - 21:59)

Thanks, as a cakephp newcomer this is brilliant to start an application and get to see how things work.
And i'm glad i've also learned about the recursive option after hours of headache when i discover that the "var $recursive = -1;" in your app_model was preventing my (new baked) controllers to retrieve all the associated data ;)
Ok i get back to the code.
Chears!

Roger grigol (15/10/2010 - 14:29)

Thanks for the article. I learned a lot with it.

mufti (27/10/2010 - 19:13)

Hi james, thanks for sharing and releasing this admin section template for free.

selvaraja (01/11/2010 - 07:32)

i am newbe in cakephp. this article is really useful for me.
Thanks keep it up.

Chris (23/12/2010 - 09:04)

No reason for commenting other than to say thanks for the blog James. I really appreciate your posts on Cake, they're always useful and have saved me an awful lot of time.

Vishwanath (02/06/2011 - 08:14)

Your article helped a lot, Thanks.

annykey (21/10/2011 - 11:22)

I've been having problems with your Admin Selection Template, and it turns out that it doesn't work for controllers with beforeFilter functions.

Quick fix is to add the contents of the app_controller beforeFilter to the beforeFilter function in the problematic controller.

Add Your Comment

Sites I've Created

DSP Chartered Surveyors Stoneylane Aberdeen Angus

Recently Watched Films

Mr Brooks Rec Pathology Diary of the Dead

TV Shows

The Shield Flight of the Conchords

Hosting

I've been using Dreamhost for my hosting for over 2 years and it's pretty good for what you pay. If you're signing up how about showing me some love and use this link so I get a referal bonus to help pay my server costs.

Site by James Fairhurst © 2008-2012, all rights reserved and all that malarky