⚠ 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 is an archived forum. ⚠

  •     

profile picture

CRUD for a subset of users



mikeh
  • profile picture
  • Member

Posted 28 January 2013 - 14:33 PM

Hi I am new to Grocery CRUD, but have managed to implement quite a lot without issues and with the help of articles found here.

One thing I am having problems with is how to go about the following.

I need to maintain a 'user list' for many offers, so have an 'Offer Table' and a linked 'User Table'. Ideally I want to display a list of Offers for the Admin to select from and then set up the CRUD to LIST/ADD/CHANGE/DELETE the User records just for that Offer.

I have a piece working which displays the list of Offers and then the filtered list of records for the selected Offer which is based on using the where clause to filter the record set using the supplied OfferID

$state = $crud->getState();
if($state=='list' && $this->uri->segment(5)==""){// need to display a form to get the offer
$this->load->model('offers_model');
$data['offers']=$this->offers_model->get_all_offers_for_select();
$this->load->view('admin/selectoffer',$data);
return;
}
if($state=='list' && $this->uri->segment(5)!=""){
$offer_id = $this->uri->segment(5);
}

$crud->set_table('user_list');
if($offer_id != ""){
$crud->where('offer_id',$offer_id);
$crud->field_type('offer_id','hidden',$offer_id);
}

$crud->columns('email','e164');
$crud->add_fields('offer_id','email','e164');
$crud->edit_fields('email','e164');
$crud->order_by('offer_id','email');

//$crud->display_as('offer_id','Offer');
$crud->display_as('email','Email Address');
$crud->display_as('e164','e.164 Number');

$crud->set_rules('email','Email Address','required');
$crud->set_rules('e164','e.164 Number','required');
//$crud->set_rules('offer_id','Offer','required');

$crud->set_relation('offer_id','offer','name',array('deleted' => 0));
log_message('debug',"***** OfferID :=" . $offer_id );


$output = $crud->render();

$this->_display_output($output);

This works OK for List, Edit and Delete, but somehow I need to get the OfferID into the ADD mode.

Any recommended ways to do this?

Thanks Mike

davidoster
  • profile picture
  • Member

Posted 30 January 2013 - 10:16 AM

Since you have the offer_id why don't you do a callback_add_field?
http://www.grocerycrud.com/documentation/options_functions/callback_add_field

mikeh
  • profile picture
  • Member

Posted 31 January 2013 - 10:34 AM

Not sure how that helps. I'm losing the offer_id when I move from the List to the Add state.

davidoster
  • profile picture
  • Member

Posted 31 January 2013 - 10:37 AM

You will not lose it if you store it in a global variable or save it in a cookie variable like grocery crud does! There are so many different ways to do it!