• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
set_value() for getting array in return

#1
[eluser]Unknown[/eluser]
Hello Everybody,

I have download the new version of codeigniter and it give me following error when I use set_value() for getting array in return.

ERROR
------
Warning (in_array() expects parameter 2 to be array, string given in file: views/add_role_view.php on line: 123)

Actually my task is to set the checked values of checkboxes after postback.

Have a look my code.
Code:
<?php
$page_id = array();
$page_id = set_value('assignRole[]');

foreach($data as $row){
?>
<input type="checkbox"  value="<?php echo($row->page_id); ?>" name="assignRole[]" <?php if(!empty($page_id) && in_array($row->page_id, $page_id)){?>checked="checked" <?php }?> />
<?php
}
?>

$row->page_id is a unique ID coming from loop send by controller in $data variable.

It was working fine in previous version i.e. 1.7.3 but when I installed the new version it going to mass.

By the way I am using version 2.1.2

Any idea??

#2
[eluser]Aken[/eluser]
set_value() needs the field name as interpreted by the server. I.E. if it's an array, leave out the array notation.

Code:
$page_id = set_value('assignRole');

#3
[eluser]Unknown[/eluser]
Thanks for your reply Aken,

I tried it with
Code:
$page_id = set_value('assignRole');
But still its not working.

Now what I did
I used the following code and its working fine.

Code:
<input type="checkbox"  value="<?php echo($row->page_id); ?>" name="assignRole[]"  <?php echo(set_checkbox('assignRole', $row->page_id));?> />

Basically I saw it later that there is a function for checkbox i.e.

Code:
set_checkbox('assignRole', $row->page_id)
which returns checked="checked" if it is checked before the form submitted.

But thanks for your prompt reply.


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2020 MyBB Group.