⚠ 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

Constant value



mneu
  • profile picture
  • Member

Posted 15 June 2012 - 15:26 PM

Hi!

I need to set a constant value to one or more fields, but i can't do it.
This is my code:


public function PortalesPropiedades()
{
if (isset($_GET['IdPropiedad']))
$_SESSION['IdPropiedad'] = $_GET['IdPropiedad'];
$this->grocery_crud->set_table('propiedadesportales');
$this->grocery_crud->where('IdPropiedad',$_SESSION['IdPropiedad']);
$this->grocery_crud->set_relation('IdPortal','portales','Portal');
$this->grocery_crud->columns('IdPortal','URL');
$this->grocery_crud->required_fields('IdPortal','URL');
$this->grocery_crud->display_as('IdPortal','Portal');
$this->grocery_crud->callback_before_insert(array($this,'PortalesPropiedadesInsert'));
$output = $this->grocery_crud->render();
$this->PortalesPropiedadesOutput($output);
}
function PortalesPropiedadesInsert($post_array) {
$post_array['idpropiedad'] = $_SESSION['IdPropiedad'];
return $post_array;
}
function PortalesPropiedadesOutput($output = null)
{
$this->load->view('vista_iframe.php',$output);
}

kenvogt
  • profile picture
  • Member

Posted 15 June 2012 - 19:06 PM

If you are trying to set session data you would do well to look at the Session class in the Codeigniter docs.

mneu
  • profile picture
  • Member

Posted 15 June 2012 - 19:07 PM

Thanks!, but is possible to insert a constant value?, another way to do that?
Thanks!

fdias
  • profile picture
  • Member

Posted 16 June 2012 - 17:14 PM

I don't know if I understood your question correctly, but do you need to have a constant default value on some of your input field?
If that's the case I would just have a callback_add_field call a function to change my input to readonly and assing the value I want to it.

Something like this:


$crud->callback_add_field('FIELD_NAME',array($this,'my_callback_function'));

function my_callback_function()
{
return '<input type="text" readonly="readonly" value="VALUE_FROM_SESSION" name="field_name">';
}


If you wish you can use also a hidden field.

Check the docs for callback_add_field:

http://www.grocerycrud.com/documentation/options_functions/callback_add_field

I hope this helps.