PHP數組在笨我有一個觀點theme-fonts.php
,我在加載另一個視圖page.php
。笨獲取從視圖
page.php
<?php $this->load->view('theme-fonts'); ?>
<script type="text/javascript">
try{
var fontsArray = <?php json_encode($font_list); ?>;
console.log(fontsArray);
}catch(err){
console.log(err.message);
}
</script>
以下是我theme_fonts.php
文件中定義:
<link href="http://fonts.googleapis.com/css?family=Aclonica" rel="stylesheet" />
<link href="http://fonts.googleapis.com/css?family=Michroma" rel="stylesheet" />
<link href="http://fonts.googleapis.com/css?family=Paytone+One" rel="stylesheet" />
<link href="http://fonts.googleapis.com/css?family=Denk+One" rel="stylesheet" />
<link href="http://fonts.googleapis.com/css?family=Wendy+One" rel="stylesheet" />
<link href="http://fonts.googleapis.com/css?family=Fjalla+One" rel="stylesheet" />
<?php
$font_list = array();
array_push($font_list,"Aclonica");
array_push($font_list,"Michroma");
array_push($font_list,"Paytone+One");
array_push($font_list,"Denk+One");
array_push($font_list,"Wendy+One");
array_push($font_list,"Fjalla+One");
?>
所以我的問題是如何從視圖theme-fonts.php
訪問PHP數組的主視圖page.php
?
問候:Jehanzeb
對不起它是不夠清楚。我想要的與你的建議相反。我想數組'$ font_list'從'主題fonts.php'到'page.php' – 2013-03-22 10:58:38
你爲什麼不以你的控制器聲明數組,然後把它傳遞到主視圖,這樣,這將是可訪問'theme-fonts.php'和'page.php'。我不確定你是如何構造這個的,但是你不能加載'page.php',並期望如果你還沒有聲明數組,它就可以使用。 – mcryan 2013-03-22 11:03:26