Hide
on 24/3/08

Happy Christmas leveille!

How would you like to be able to generate your entire admin backend in one call? Not interesting enough? How about with built in index filters and by writing practically no code? Well... keep reading then :).

The code

The code I am discussing here is available from the Noswad cakeforge project. Be sure to read the release note.

What's in the new download?

There are a few supporting files in the download - Bake templates themselves obviously have no dependencies, however the example code my templates generate do so they are included to hopefully demonstrate/inspire how to get the most out of custom templates and bake. So, the contents:

Tweaked tasks

The controller task has been modified only to prevent the inclusion of the helpers var (with the included app controller file, no code at all is required in controllers by default), the view task has been modified to pass the schema data to the view template to allow some fine-tunning based on field types. There's a ticket requesting this change.

A layout

Yeah how exciting :). A default admin layout is included in the download to allow the downloaded files to work out of the box.

JS and CSS files

A small amount of jquery is used in displaying and hiding the filter form - there's also a default admin css included.

Tree Helper

Although not strictly necessary the admin menu is generated via the Tree Helper.

Filtering element and controller logic

This is the bit that I assume will get some interest and hope will stop "pagination and filtering" coming up on the google group.

Included in the previously released (v0.1) bake templates was the possibility to zero-in on data applying PRG style filters by clicking on the values in the table to limit the results for that column to a specific value. For small and evenly distributed result sets this works well; if you are looking at your blog listings and see the last 20 posts, which includes at least one post by each of John, Bob, and Gerald you can click on Bob's name to see the last 20 posts by Bob only. Then, if you want to see only posts in category "Boat" you click on category "Boat" and see the last 20 posts by Bob, in category Boat - and on you can go until your filter is as long as you like. However, what happens when you have massive datasets and complex filtering requirements - where filtering your result sets is not a nice-to-have but a necessity? How can you (or a user) easily apply a filter to find the 3 Widgets of type x, when there are thousands of entries in the database and none of them are in the initial index to be clicked upon? How do you find all posts for the months of January and February? Or all products more than 10$..?

Well, I guess the answer is obvious: a filter form. So in addition to the table-cell PRG style links for fine tuning if required, the new bake templates add a filter form to all index pages.

Wrapping Up

Bake is awesome. running bake and getting all admin views in a single console call is awesome-er, running bake and getting pretty much a fully working admin backend in a single call is still more awesome, making a db change, running bake and getting a fully functional admin backend with which you (typically) only need to comment out the few things you don't need to be done is awesome-est :). The results of the new bake templates may still need some tweaking so as I'm in agreement with a previous commenter this cake goodie goes out here on the blog.

Bake on!

8 Responses to Bake yourself a complete admin backend - in one call

  1. 1

    So, I'm commenting before reading the article, but trust me, the article is definitely going to be read. Upon seeing my last name I was like, holy moly, my name is showing up in this post! How is that happening. Than I remembered our IRC chat ... Ad7Six's posts are my Christmas morning presents!

  2. 2

    Hey, your idea sounds good. Gonna give it a try today.

  3. 3

    Some install instructions would be great. After making some assumptions and trying a few things. I am still not getting it to work properly.

    Asumeing that I cake bake normally 3 times (for skel (with ur app folder added), database, and a Model), then create an empty controller for that model, I then run 'cake bake_admin apples' and get my admin views. It didnt find the views however..

  4. 4

    I'm not sure what install instructions would be useful; you need to know how to run console tasks to be able to run a specific console task, and the zip file is a "paste over" zip for an existing install. You put the vendor files in the vendor folder, and the app files in the app folder of an existing install (if you want to use them at all that is. You can read specifically about the bake admin script on the bakry.

  5. 5
    Ah. Well there we have it then. My first assumption was incorrect, so all that followed failed to naturally. I tried to put all your files in the console folders. Copying them in those subfolders they seem to match. So the app dir goes directly in a normally baked app? And the vendors/shells goes in cake\console\libs? And tasks goes there too? Albeit in a level above? There are no vendors folder in my cake install though, so it's a bit confusing. Are you using cake 1.2 pre-beta?
  6. 6
    Ok i think i got it all installed properly. If I change the install package from you by putting the vendors folder inside the app folder and renaming the template views to admin_index, admin_edit and admin_view and and copying the app folder into an existing app I get it installed properly. The next issue then is to have the app baked in a proper way for the bake_admin script to work. The biggest change is the addition of baking the scheme that needed a core script edit (require_once "string.php") to work. The last problem I am battleing now, is that your app_controller bakes out all data in $this->data, while your view expects them as a $pluralmodelname. I have so far been unsuccessfull in changing your admin_index view template to satisfy this need, but I can do it in the baked view.
  7. 7
    "making a db change" Do you mean copy and duplicating the DB or modifying the db?
  8. 8
    "A small amount of jquery is used in displaying and hiding the filter form - there's also a default admin css included." This looks great