Well this is just a recommendation for how to create an extension and add it to the forum. This is very useful if you want to share your code and make it updatable with newer versions of grocery CRUD.
The below example works fine and you can use it to your project also if you like it.
First of all you have to describe what this patch/extension is doing and how much it helps you to solve some problems you have.
For example:
[quote]
This extension logs the date - time that someone insert or update the database with the CRUD. If the fields "created" and "updated" exists at the table then automatically add the datetime to log the date and the time updated/created. It really helped me as I don't write the same auto queries again and again and I wanted to share it with you. It works fine with DATETIME type and TIMESTAMP type.
[/quote]
Second thing that you have to do is to share all the code to the forum with the code tags. Even if you have attached the file into the post, you have to show to the topic the code (or if there are lot of changes a big part of the code).
For example:
class MY_grocery_Model extends grocery_CRUD_Model{
function db_update($post_array, $primary_key_value)
{
if ($this->field_exists('updated'))
{
$this->load->helper('date');
$post_array['updated'] = date('Y-m-d H:i:s',now());
}
return parent::db_update($post_array, $primary_key_value);
}
function db_insert($post_array)
{
if ($this->field_exists('updated') && $this->field_exists('created'))
{
$this->load->helper('date');
$post_array['created'] = date('Y-m-d H:i:s',now());
$post_array['updated'] = date('Y-m-d H:i:s',now());
}
return parent::db_insert($post_array);
}
}
So as you see from the example we created a class named MY_grocery_Model that extends [color=#2C575B][font=Arial, Tahoma, Helvetica, sans-serif]grocery_CRUD_Model[/font][/color]. This is very useful for the library to be updated with a new version of grocery CRUD. The same thing of course is a good practice to do with the basic library so for example if we want to create an extension for grocery CRUD we can just create an extension with name MY_grocery_CRUD that extends grocery_CRUD.
The next step is to explain how to install the patch so in our case we have:
[quote]
Save this code in a file named : my_grocery_model.php at the folder application/models/ or download the attached file and copy it to application/models/ . The only thing now that you have to do is everytime that you want to use this model just add this line of code to your crud function:
$crud->set_model('MY_grocery_Model');
and that's it.
[/quote]
You can either copy the code or download the [attachment=69:my_grocery_model.php] attached file.