Welcome Guest, Not a member yet? Register   Sign In
Table Generate() creating td with all values as attributes within td tag
#1

[eluser]ray023[/eluser]
The following code:
Code:
$this->load->library('table');
  
  $my_row["car_id"]= "1";
  $my_row["nickname"] =  "Bessie" ;
  $my_row["year"]=  "1975" ;
  $my_row["model"]=  "Bug" ;
  $my_row["engine"]=  "Water-Cooled" ;
  $my_row["owned"]= "0/0/0000" ;
  $my_row["sold"]= "0/0/0000" ;
  $my_row["for_sale"]=  "No" ;
  $this->table->add_row($my_row);
  
  $local_table = $this->table->generate();
  echo 'local table:<br>';
  echo $local_table;
  echo 'end of lcoal table<br>';

Produces the following html:
Code:
<table cellspacing="0" cellpadding="4" border="0">
<tbody>
  <tr>
   <td car_id="1" nickname="Bessie" year="1975" model="Bug" engine="Water-Cooled" owned="0/0/0000" sold="0/0/0000" for_sale="No"></td>
   <td>1</td>
   <td>Bessie</td>
   <td>1975</td>
   <td>Bug</td>
   <td>Water-Cooled</td>
   <td>0/0/0000</td>
   <td>0/0/0000</td>
   <td>No</td>
  </tr>
     </tbody>
</table>

Notice how the first td contains all the values and renders a blank column.

I have similar code in an older version of CI (pre 2.0) and it works fine; but for some reason, the above out happens on my CI 2.0 project.

I've stepped through table.php and nothing is jumping out to me that looks wrong.

However, if I add the following lines above line 191 in table.php:
Code:
echo '<br>';
var_dump($args);
echo '<br>';

NOTE: Line 191 in table.php for me looks like this:
Code:
$args[$key] = array('data' => $val);
this is in function _prep_args.

I get output that looks like this:
Quote:array(1) { [0]=> array(8) { ["car_id"]=> string(1) "1" ["nickname"]=> string(6) "Bessie" ["year"]=> string(4) "1975" ["model"]=> string(3) "Bug" ["engine"]=> string(12) "Water-Cooled" ["owned"]=> string(8) "0/0/0000" ["sold"]=> string(8) "0/0/0000" ["for_sale"]=> string(2) "No" } }

array(2) { [0]=> array(8) { ["car_id"]=> string(1) "1" ["nickname"]=> string(6) "Bessie" ["year"]=> string(4) "1975" ["model"]=> string(3) "Bug" ["engine"]=> string(12) "Water-Cooled" ["owned"]=> string(8) "0/0/0000" ["sold"]=> string(8) "0/0/0000" ["for_sale"]=> string(2) "No" } ["car_id"]=> array(1) { ["data"]=> string(1) "1" } }

array(3) { [0]=> array(8) { ["car_id"]=> string(1) "1" ["nickname"]=> string(6) "Bessie" ["year"]=> string(4) "1975" ["model"]=> string(3) "Bug" ["engine"]=> string(12) "Water-Cooled" ["owned"]=> string(8) "0/0/0000" ["sold"]=> string(8) "0/0/0000" ["for_sale"]=> string(2) "No" } ["car_id"]=> array(1) { ["data"]=> string(1) "1" } ["nickname"]=> array(1) { ["data"]=> string(6) "Bessie" } }

array(4) { [0]=> array(8) { ["car_id"]=> string(1) "1" ["nickname"]=> string(6) "Bessie" ["year"]=> string(4) "1975" ["model"]=> string(3) "Bug" ["engine"]=> string(12) "Water-Cooled" ["owned"]=> string(8) "0/0/0000" ["sold"]=> string(8) "0/0/0000" ["for_sale"]=> string(2) "No" } ["car_id"]=> array(1) { ["data"]=> string(1) "1" } ["nickname"]=> array(1) { ["data"]=> string(6) "Bessie" } ["year"]=> array(1) { ["data"]=> string(4) "1975" } }

array(5) { [0]=> array(8) { ["car_id"]=> string(1) "1" ["nickname"]=> string(6) "Bessie" ["year"]=> string(4) "1975" ["model"]=> string(3) "Bug" ["engine"]=> string(12) "Water-Cooled" ["owned"]=> string(8) "0/0/0000" ["sold"]=> string(8) "0/0/0000" ["for_sale"]=> string(2) "No" } ["car_id"]=> array(1) { ["data"]=> string(1) "1" } ["nickname"]=> array(1) { ["data"]=> string(6) "Bessie" } ["year"]=> array(1) { ["data"]=> string(4) "1975" } ["model"]=> array(1) { ["data"]=> string(3) "Bug" } }

array(6) { [0]=> array(8) { ["car_id"]=> string(1) "1" ["nickname"]=> string(6) "Bessie" ["year"]=> string(4) "1975" ["model"]=> string(3) "Bug" ["engine"]=> string(12) "Water-Cooled" ["owned"]=> string(8) "0/0/0000" ["sold"]=> string(8) "0/0/0000" ["for_sale"]=> string(2) "No" } ["car_id"]=> array(1) { ["data"]=> string(1) "1" } ["nickname"]=> array(1) { ["data"]=> string(6) "Bessie" } ["year"]=> array(1) { ["data"]=> string(4) "1975" } ["model"]=> array(1) { ["data"]=> string(3) "Bug" } ["engine"]=> array(1) { ["data"]=> string(12) "Water-Cooled" } }

array(7) { [0]=> array(8) { ["car_id"]=> string(1) "1" ["nickname"]=> string(6) "Bessie" ["year"]=> string(4) "1975" ["model"]=> string(3) "Bug" ["engine"]=> string(12) "Water-Cooled" ["owned"]=> string(8) "0/0/0000" ["sold"]=> string(8) "0/0/0000" ["for_sale"]=> string(2) "No" } ["car_id"]=> array(1) { ["data"]=> string(1) "1" } ["nickname"]=> array(1) { ["data"]=> string(6) "Bessie" } ["year"]=> array(1) { ["data"]=> string(4) "1975" } ["model"]=> array(1) { ["data"]=> string(3) "Bug" } ["engine"]=> array(1) { ["data"]=> string(12) "Water-Cooled" } ["owned"]=> array(1) { ["data"]=> string(8) "0/0/0000" } }

array(8) { [0]=> array(8) { ["car_id"]=> string(1) "1" ["nickname"]=> string(6) "Bessie" ["year"]=> string(4) "1975" ["model"]=> string(3) "Bug" ["engine"]=> string(12) "Water-Cooled" ["owned"]=> string(8) "0/0/0000" ["sold"]=> string(8) "0/0/0000" ["for_sale"]=> string(2) "No" } ["car_id"]=> array(1) { ["data"]=> string(1) "1" } ["nickname"]=> array(1) { ["data"]=> string(6) "Bessie" } ["year"]=> array(1) { ["data"]=> string(4) "1975" } ["model"]=> array(1) { ["data"]=> string(3) "Bug" } ["engine"]=> array(1) { ["data"]=> string(12) "Water-Cooled" } ["owned"]=>

Notice how it appends array items to the end of already existing array.

Any thoughts on how to fix this problem?


<b>NOTE:</b> I just downloaded CI 2.1, extracted it and replaced the welcome controller with the above code. Same result.
#2

[eluser]ray023[/eluser]
Think I got it.

As mentioned earlier, since I can do this with CI 2.1, I believe this is a bug.

In Table.php, it works if I change this:
Code:
if ( ! isset($args[0]['data']))
   {
    foreach ($args[0] as $key => $val)
    {
     if (is_array($val) && isset($val['data']))
     {
      $args[$key] = $val;
     }
     else
     {
      $args[$key] = array('data' => $val);
     }
    }
   }
to this:
Code:
if ( ! isset($args[0]['data']))
   {
    $ret_args = array();
    foreach ($args[0] as $key => $val)
    {
     if (is_array($val) && isset($val['data']))
     {
      $ret_args[$key] = $val;
     }
     else
     {
      $ret_args[$key] = array('data' => $val);
     }
    }
    $args = $ret_args;
   }

Created bug tracker issue




Theme © iAndrew 2016 - Forum software by © MyBB