0

我在工作中使用ASP.NET MVC3,而在家中使用PHP。我希望在CodeIgniter中使用MVC3的Sections功能,它有这样的功能吗?在ASP.NET MVC3在CodeIgniter中使用部分

实施例(未测试):

<!-- A view, that serves the content --> 
@section Head{ 
    <script src="myscript.js"></script> 
} 
<p>This is my main content - 
I require myscript.js to be included on my page, 
so I specify a head section, which the header of my page will render</p> 



<!-- ANOTHER view, that serves the content --> 
@section Head{ 
    <script src="otherscript.js"></script> 
    <link rel="stylesheet" type="text/css" href="somestyle.css" /> 
} 
<p>Some OTHER view, with OTHER dependencies!</p> 





<!-- Header File, where I include CSS and JS! --> 
<head> 
<script src="jquery.js"></script> 

@Html.Section("Head") 

</head> 

的点被,例如,在特定的视图中,我希望包括一个脚本文件,所以我添加<script>到第,并且该部分在页眉中呈现(在不同的视图中)

+0

为什么不使用'$ this-> load-> view('child_view_name');'在父视图中? – Tim 2012-08-13 18:33:09

+0

你能告诉我一个如何实现我的目标的例子吗? :) – Jeff 2012-08-13 18:54:08

+0

在我看来,你只需要将HTML的一部分添加到另一部分,对吧?如果是,那么从另一个视图加载视图看起来对我来说是个好主意。 – Tim 2012-08-13 19:13:53

回答

2

对于部分模板的概念或您可以在视图中包含的子视图,似乎为@Section is just some syntactic sugar

在CodeIgnier中,这只是在加载主视图时加载到控制器中的另一种视图,并自定义包含主视图的HTML。要在CodeIgniter中加载多个视图,请参阅here

当然,这只是如果你想自己连线,as seen here。更好的方法是使用模板库。有many template libraries available for CodeIgniterSome people have asked for comparisons,菲尔鲟鱼似乎很受欢迎(并做你想做的)。

+0

我编辑了OP - 这些有助于我达到预期效果吗?我似乎无法找到任何相关的东西。 :) – Jeff 2012-08-13 19:57:17