15 Nov 2009 @ 11:23 AM 

If you are looking for an easy to use CRUD (Create, Read, Update, Delete) framework for PHP, then I can *highly* recommend Rapyd.

Although Rapyd is a MVC (Model/View/Controller) framework http://www.rapyd.com/, I am using the version of Rapyd that integrates with CodeIgniter

The only shortcoming is that the documentation is rather lacking, so I had to figure most of it out myself.

While there are some excellent examples on the Rapyd website, I have decided to add some examples of my own.

<?php
class hardware_list extends MY_Controller
{
    function hardware_list()
    {
        parent::MY_Controller();
        $this->load->library('rapyd');
        $this->title = 'Manage hardware';
    }
 
    //put your code here
    function edit_data()
    {
        $hardware_edit = new dataedit_library();
        $hardware_edit->label = $this->title;
        $hardware_edit->back_url = site_url('hardware_list');
 
        $hardware_edit->source('hardware');
        $hardware_edit->field('input','hw_serial','Serial Number');
        $hardware_edit->field('input','hw_desc','Description');
        $hardware_edit->field('radiogroup','hw_status','Status')->options(array("1"=>"Enabled", "2"=>"Disabled"));
        $hardware_edit->field('radiogroup','hw_type','type')->options(array("1"=>"Wintec", "2"=>"Stand Alone PC"));
        $hardware_edit->buttons('modify','save','undo','back','delete');
        $hardware_edit->build();
        $data['head']    = $this->rapyd->head();
        $data['title']   = $this->title;
        $data['content'] = $hardware_edit->output.'<br />';
        $data['current_selected_nav_item'] = 6;
        $this->load->view('terminals/terminals', $data);
    }
 
function index()
    {
        if ($this->rapyd->qs->value('show|delete|modify|create|insert|update'))
        {
            $this->edit_data();
        } else
        {
            $hardware_grid = new datagrid_library();
            $hardware_grid->label = $this->title;
            $hardware_grid->source('hardware');
            $hardware_grid->column('hw_serial','serial', true)
                ->url(site_url('hardware_list/?show={hw_serial}'))
                ->rule('required');
            $hardware_grid->column('hw_status','Status');
            $hardware_grid->column('hw_type','Type');
            $hardware_grid->column('hw_desc','Description');
            $hardware_grid->column('delete', 'delete')->url(site_url('hardware_list/?delete={hw_serial}'));
            $hardware_grid->buttons('add');
 
            $hardware_grid->build();
 
            $data['head']    = $this->rapyd->head();
            $data['title']   = $this->title;
            $data['content'] = $hardware_grid->output.'<br />';
 
            $data['current_selected_nav_item'] = 6;
 
            $this->load->view('terminals/terminals', $data);
       }
    }
}
 
?>

I want to make a note about the “events” and the order that they happen in, as it took me quite a while to figure it out.

create = before insert – show the form with empty fields
insert = after insert – this happens after create and physically inserts the fields into the db
delete = before delete – show confirmation screen
do_delete = after delete is confirmed – this physically deletes the row from the db
show = show all the info for a single row, but edit it just yet
modify = before data is modified – it shows the edit form with all the fields populated
update = save changes entered in the modify screen

Your “source” can also be an active record result set eg

$grid->label = $this->title;
$grid->db->select('user.*,customer.company_name');
$grid->db->from('user');
$grid->db->join('customer', 'user.customer_id = customer.customer_id');
$grid->db->where('user.customer_id = ' . $customer_id);
Posted By: Zayin
Last Edit: 15 Nov 2009 @ 11:40 AM

EmailPermalink
Tags
Tags: , ,
Categories: php, rapyd


 

Responses to this post » (5 Total)

 
  1. zayinkrige says:

    New Blog Post -> Rapyd – CRUD for PHP – part 2 – http://www.zayinkrige.com/rapyd-crud-for

  2. zayinkrige says:

    New Blog Post -> Rapyd – CRUD for PHP – Part 4 – Validation – http://www.zayinkrige.com/rapyd-crud-for

  3. zayinkrige says:

    New Blog Post -> Rapyd – CRUD for PHP – Part 4 – Editing Data – http://www.zayinkrige.com/rapyd-crud-for

  4. zayinkrige says:

    New Blog Post -> Rapyd – CRUD for PHP – Styling – http://www.zayinkrige.com/rapyd-crud-for

  5. Daniel says:

    great post, thanks for sharing

Post a Comment

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

Please note: Comment moderation is enabled and may delay your comment. There is no need to resubmit your comment.


 Last 50 Posts
 Back
Change Theme...
  • Users » 1
  • Posts/Pages » 40
  • Comments » 64
Change Theme...
  • VoidVoid « Default
  • LifeLife
  • EarthEarth
  • WindWind
  • WaterWater
  • FireFire
  • LightLight

Links



    No Child Pages.

Portfolio



    No Child Pages.