我试图将数组数据从控制器传递到视图,但是视图丢失了"Yii格式“(头引导),标题没有出现,只显示”平面文本“。
当我尝试用array_pop提取元素时,就会发生这种情况。
视图: magazines.php
<?php
/* @var $this SiteController */
$this->pageTitle=Yii::app()->name;
?>
<h3>
<?php
$aux_string = "";
foreach ( $files_format as $aux_string ) {
$aux_string->array_pop($files_format);
}
?>
</h3>控制器: SiteController.php
public function actionMagazines()
{
$path="pdfs/";
$directory=dir($path);
$files=array();
while (false !== ($entry = $directory->read()))
{
if($entry!="."&&$entry!=".."){
array_push($files, $entry);
print_r($files);
}
}
$this->render('magazines', array('files_format'=> $files));
}另一方面,如果我不使用array_pop,"Yii格式“将保持完整(下面是正确显示视图的带有array_pop注释的代码行)
...
//$aux_string->array_pop($files_format);
...发布于 2013-10-03 08:18:29
我觉得你想做的是:
$aux_string = "";
foreach ( $files_format as $string ) {
$aux_string.=$string ;
}或者:
$aux_string = join('',$files_format);发布于 2013-10-03 09:06:26
实际上,通过更改foreach循环中的一行代码就可以解决这个错误。
为此,我理解“视图”的问题在于手动处理堆栈;而foreach在内部以自动模式进行处理。
视图: magazines.php
<?php
/* @var $this SiteController */
$this->pageTitle=Yii::app()->name;
?>
<h3>
<?php
$aux_string = "";
foreach ( $files_format as $aux_string ) {
echo $aux_string."<br><br>";
}
?>
</h3>https://stackoverflow.com/questions/19136362
复制相似问题