Ich benutze Codigniter für ein Projekt und müssen Importfunktion hinzufügen. Ich versuche, die geparste CSV-Datei als ein Array an die Ansicht übergeben, aber das Array scheint leer zu sein, wenn ich es übergeben.Codeigniter nicht übergeben Array zu sehen
hier ist die Methode, die csv und lädt die Ansicht
public function confirm($targetFile){
$data = array(
'import_url' => site_url(array('import', 'confirm'))
);
$data = array();
$config = new LexerConfig();
$lexer = new Lexer($config);
$interpreter = new Interpreter();
$i=0;
$data_array =array();
$interpreter->addObserver(function(array $columns) use (&$i, &$data_array){
if($i == 0){
$i = $i + 1;
}else{
array_push($data_array,$columns);
}
return $data_array;
}
);
$lexer->parse($targetFile, $interpreter);
print_r($data_array);
// $j=0;
// while($j < sizeof($data_array)){
// $valid = $this->validateRow($data_array[$j],$j);
// if($j == 0){
// //print_r($data_array[$j]);
// }
// if($valid){
// //echo 'true';
// }else{
// //echo 'false';
// }
// $j++;
// }
return $this->load->view('import/view',$data_array); ;
}
im Verfahren
Hier ist der Ansicht
<?php $this->load->view('include/site_header'); ?>
<?php
if(!empty($data_array)){
foreach((array)$data_array as $data){
print_r($data[0]);
}
}
?>
<div id="content" class="gradient gray">
<h1 class="header">
Import Contacts</h3>
<form id="import_form" action="" method="post" target="_blank">
<h2 class="header">
Confirm import</h3>
<fieldset id="fields">
<div class="clearfix">
<table style="width:100%;">
<tr>
<td>fname</td>
<td>lname</td>
<td>company</td>
</tr>
</table>
</div>
</fieldset>
</form>
</div>
<?php $this->load->view('include/site_footer'); ?>
Seine interessant, weil das Array nicht leer ist parst nach es wird geparst.
Array (
[0] => Array ([0] => 1 [1] => Kathleen [2] => L[3] => [email protected]ysite.com [4] => Female [5] => 111.111.44.111)
[1] => Array ([0] => 2 [1] => Craig [2] => >G[3] => [email protected] [4] => Male [5] => 111.111.77.111)
[2] => Array ([0] => 3 [1] => Kathy [2] => R[3] => [email protected] [4] => Female [5] => 111.111.88.111)
[3] => Array ([0] => 4 [1] => Annie [2] => R[3] => [email protected] [4] => Female [5] => 111.111.99.111)
[4] => Array ([0] => 5 [1] => Chris [2] => D[3] => [email protected] [4] => Male [5] => 111.111.66.111)
)
was in 'print_r ($ data_array) ausgegeben wird;'? Könntest du die Ausgabe posten? –
Ich habe es gerade hinzugefügt –
versuchen Sie unter Antwort. –