unset_delete per row
- Single Page
Posted 01 June 2013 - 23:33 PM
I've been searching in the forum but i couldn't find a topic that could help me solve my doubt.
How can I unset the delete button conditioned from a return from a select in another table?
I need to get the primary key from the list (main table) and make a select in another table using this primary key. If the result returns more than zero, in other words, if it found records unset delete button.
I've tried using callbacks but without sucess.
Anyone could help me?
Thanks.
Posted 02 June 2013 - 07:57 AM
Well the logic behind this would be something like the following,
1. make a function that accepts table, field and returns on an array class variable (lets say $table_rows) all the row->id => true/false combinations
2. unset_delete
3. call the add_action and foreach $row->id if($table_rows[$row->id]) display the delete button.
Posted 02 June 2013 - 11:01 AM
Sorry but I didn t undertand completely. The step 1 should be to get records from my list?
Isn t there any way to get primary key from list using getStateInfo like edit state?
I need to get every pk from list and use it on a where condition. If it returns true unset delete.
Posted 02 June 2013 - 12:36 PM
You need to have a custom model where you access your database.
On the function that access the database you store on an array all the true/false per row.
Then you use this function (that returns this array) within your controller and within your add_action in order to show or not the delete button.
Posted 02 June 2013 - 18:36 PM
David, thanks for your reply...
Do you have an example?
Posted 04 June 2013 - 02:09 AM
Hi,
I'm looking at the documentation page and other links for the set_model function but I'm not sure how to use it.
In the documentation example I see that inside the model a function named "get_relation_n_n_unselected_array" is defined, but I don't know how to use this function.
If I define my custom model can I set my own custom function names or should I use defined GC names?
How can I use on the controller my custom function from my custom model?
Please, could someone give me some more explanations or code examples about how to use set_model?
Thanks
Posted 04 June 2013 - 09:28 AM
You don't need to extend the GC model for this.
Check here: http://ellislab.com/codeigniter/user-guide/general/models.html
Posted 04 June 2013 - 14:48 PM
Ok, but even if i extend GC model how do I use it on the controller?
Just adding the line $crud->set_model('my_model') will works?
How can I call my methods after I set the line above?
Posted 04 June 2013 - 22:17 PM
Sample code follows:
// file itemmodel.php <?php class itemmodel extends CI_Model { function __construct() { parent::__construct(); $this->load->database(); } public function get_by_id($table, $id) { $this->db->where('id', $id); return $this->db->get($table); } }
// within the controller function cb_send_cust_email_after_insert($post_array,$primary_key) { $this->load->model('itemmodel'); $table = 'customers_emails'; $row = $this->itemmodel->get_by_id($table, $primary_key)->row(); $data['from_name'] = $row->from_name; $data['from_email'] = $row->from_email; ... }
Posted 05 June 2013 - 02:21 AM
David, thanks for your help.