Skip to content
World Wide Web Server edited this page Jul 4, 2012 · 12 revisions

Acicrud (Automatic CodeIgniter Create Replace Update Delete)is a CRUD library that provides a ready-to-use and fully functional Model for all of your application tables.

The 2009-12-30 release have been fully tested and is currently used in production environment by more than 15 web applications over the Web.

Please se the [url=http://www.kromack.com/acicrud-english/]Acicrud project's home in english[/url] or in [url=http://www.kromack.com/acicrud/]french[/url] for downloading,API documentation, tutorials and support.

Please note that currently, Acicrud can fully (and only) manage a table for which at least the first normal form is applicable.

[i]I know this library is less powerfull that an ORM library, but Acicrud can be very suitable for rapid developpement, so I'm sharing ![/i]

Some exemples are available below :

[h3]Creating a Model[/h3] [code] <?php

class Exemple extends Acicrud {

//CONSTRUCTOR   

public function __construct()
{
    parent::__construct('table_name');
}

//CUSTOM METHODS

}

?> [/code]

[h3]Reading a row[/h3] [code] <?php

$this->load->model('exemple');

try { $exemples = $this->exemple->read(1); //Primary key id } catch(Exception $e) { echo "Wrong ID"; }

var_dump($o);

//Produces /* object(stdClass) (4) { ["idExemple"]=> string(2) "1" ["title"]=> string(8) "title..." ["description"]=> string(15) "description..." ["date"]=> string(19) "2009-04-30 21:00:00" } */

?>[/code]

[h3]Reading 10 rows[/h3] [code] <?php

$this->load->model('exemple');

try {

//Retrieve an array of objects, this array can be passed to a view for displaying data
foreach($this->exemple->getAll(10, array('date', 'DESC')) {

    var_dump($o); 

    //Produces
    /*
    object(stdClass) (4) {
      ["idExemple"]=>
      string(2) "the id"
      ["title"]=>
      string(8) "the title"
      ["description"]=>
      string(15) "the description"
      ["date"]=>
      string(19) "the date"
    }
    */
}

} catch(Exception $e) { echo $e->getMessage(); }

?>[/code] [h3]Creating a row (with form_validation)[/h3] [code] <?php

class Form extends Controller {

public function index()
{    
    //Form_validation stuff
    $this->load->library('form_validation');

    $this->form_validation->set_rules('title', 'Title', 'required');
    $this->form_validation->set_rules('description', 'Description', 'required');

    if ($this->form_validation->run() == FALSE)
    {
        $this->load->view('myform');
    }
    else
    {
        //Validation success
        $this->load->model('exemple');

        $o->title = $this->input->post('title');
        $o->description = $this->input->post('description');
        $o->date = date("Y-m-d H:i:s");

        //Creating the row in the database
        $this->exemple->create($o);
    }
}
}

?>[/code] [h3]Deleting a row[/h3] [code] <?php

class Element extends Controller {

public function Element()
{
    parent::Controller();    
    $this->load->model('elementModel');
}

public function deleteElement($id)
{
    try {

        //Try to read the row identified by $id
        $element = $this->elementModel->read($id);

        //Delete the database row
        $this->elementModel->delete($element->id);

    } catch(Exception $e) {

        die('Bad id');

    }
}

} ?>[/code]

Clone this wiki locally