⚠ In case you've missed it we have migrated to our new website, with a brand new forum. For more details about the migration you can read our blog post for website migration. This forum is read-only and soon will be archived. ⚠


Member Since 21 Oct 2013
Offline Last Active Oct 29 2013 07:27 PM

Topics I've Started

callback_after_insert and update in not working

24 October 2013 - 07:16 PM


     I am new to grocery crud as well as codeigniter. I am using following function for call_back but I is not working.


I am using 2 tabels


table_route(route_id(primarykey, autoincriment), fromcity_id, fromcity_name, tocity_id,tocity_name)


I am using set_relation for fromcity_id and tocity_id fields from table_route with city_id field in table_city


as with this set_relation I am only able to store city_id in in fromcity_id and tocity_id fields, I would also like to add city_name in fromcity_name and tocity_name fields. so I am using callback_after_insert and update functions to update citynames of the same table. my code as fallows.


public function manageroute() {
$crud = new grocery_CRUD();
$crud->callback_after_insert(array($this, '_update_cityname_after_insert'));
$crud->callback_after_update(array($this, '_update_cityname_after_update'));         
$output = $crud->render();
function _update_cityname_after_insert($post_array,$primary_key)
     $fquery = $this->db->get_where('table_city', array('city_id' => $post_array['fromcity_id']));
      $fromcityname = $fquery->city_name;
    $tquery = $this->db->get_where('table_city', array('city_id' => $post_array['tocity_id']));
    $tocityname = $tquery->city_name;
     $data = array(
               'fromcity_name' => $fromcityname,
               'tocity_name' => $tocityname               
      $this->db->where('route_id', $primary_key);
      $this->db->update('table_route', $data); 
    return true;


even I am not able echo any text from call back function.

am I doing any mistake in above code?

Need help in set_relation_n_n custom query

22 October 2013 - 12:35 PM

I have two tables 


citytable:   city_id, city_name


routetable:   route_id, fromcity_id, tocity_id


I would like to show two fields

fromcity_id is first field which is a combo where all city_name values will be displayed.


for that I wrote fallowing code.


for second field
tocity_id, I would like to display two lists.
in one list I want show all the values of tocity_id which are not exists in the route for the selected value in the comobo.
  select city_id  from citytable,routetable where
                                                   city_id notequalsto (value selected in firstcombo)
                                                   city_id notequalsto (select tocity_id from routetable where fromcity_id equalsto  (value selected in firstcombo) )
in anotherlist I want to show all the tocity_id which are already exists in the route for the selected value in the combo.
  select tocity_id from routetable where 
                                                   tocity_id qualsto (value selected in firstcombo) 
Now I can move values by selecting value from first list and add them to second list. I need this type of relation. which i saw in set_relation_n_n. but there are three tables relation.
here I need from two tables only.
one more alternative even if I can able to display values of first list  which means of first query in a combo as a second field then also my requirement will be satisfied, without using two lists.
Can you please suggest me the best practice using grocery crud.