我試圖從控制器傳遞數組數據到視圖,但視圖丟失了「Yii格式」(標題引導程序),標題不顯示,只顯示「平面文字」。Yii和array_pop在視圖中到達作爲第二個參數
當我嘗試使用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);
...
不完全;不過,你已經完成了,我明白了我用foreach構造犯的錯誤。乾杯克勞德! –
錯誤是我不瞭解foreach子句。我認爲還需要提取循環中的值(放入方括號中)。另一方面,這是foreach(迭代器)。 –