Provides New (Create), Index & Show (Read), Edit (Update), Delete functionality for the given model.
See example/ folder.
Extends Route class and adds set_crud()
method. Use like this in your init.php
:
<?php
Route::set_crud(
'user', # route prefix - will create user_index, user_new, user_edit, user_delete
'users', # uri prefix - will create users, users/new, users/<id>/edit, users/<id>/delete
'user', # controller - this controller should extend Controller_Crud
false, # skip show - if true, forwards /users/<id>, to /users/<id>/edit instead of show route
'username' # guid - default is id. routes become /users/<username>/edit, etc
);
Your controller/user.php
file would then contain:
<?php
class Controller_User extends Controller_Crud {
protected $model = 'user';
protected $route = 'user';
protected $form = 'Form_User'; # *
protected $search_fields = array('username', 'first_name', 'last_name', 'email');
}
* See FormManager module.
See the examples/views/user
folder for examples of view files. These are Smarty views, but should be easy enough to convert back to PHP. If you're not using my Pagination module, then you can access $result
instead of $pagination->result()
and remove all references to $pagination
.
The markup in the views uses Bootstrap 2.
There is no authentication provided, so you probably want to extend this in something like Controller_Crud_Admin and add whatever security you want, then extend this class instead.