Reusing Views for CRUD
Posted by Felix Geisendörfer, on Feb 09, 2006 - in PHP & CakePHP » Controllers, Components & Shells
Deprecated post
The authors of this post have marked it as deprecated. This means the information displayed is most likely outdated, inaccurate, boring or a combination of all three.
Policy: We never delete deprecated posts, but they are not listed in our categories or show up in the search anymore.
Comments: You can continue to leave comments on this post, but please consult Google or our search first if you want to get an answer ; ).
As he did once before, tobius inspired me to write some code again. This time he was trying to make scaffolding more individual, so the first thing I pointed out to him was my blog post about using generateFields for using some of the scaffolding powers. Now one problem remained: He wanted to use the same views over and over again so I had an idea about how to reuse views in a simple and efficient manner.
Here is what I did:
app/app_controller.php
-
/* This is our AppController that will help us to use 4 common CRUD views */
-
class AppController extends Controller
-
{
-
function render($action=null, $layout=null, $file=null)
-
{
-
{
-
parent::render('../crud/'.$this->action, $layout, $file);
-
}
-
else
-
{
-
parent::render($action, $layout, $file);
-
}
-
}
-
}
app/items/items_controller.php
-
/*
-
This is a sample items controller with basic CRUD functions
-
*/
-
class ItemsController extends AppController
-
{
-
-
function create()
-
{
-
// This will use app/views/items/create.thtml
-
$this->render('create');
-
}
-
-
function read()
-
{
-
// This will use app/views/crud/read.thtml
-
}
-
-
function update()
-
{
-
// This will use app/views/crud/update.thtml
-
}
-
-
function delete()
-
{
-
// This will use app/views/crud/delete.thtml
-
}
-
-
}
I hope it's useful to somebody out there ; ).



0 Comments
No comments yet...