gpt4 book ai didi

php - 带有 Yii 框架的 HTML5Boilerplate

转载 作者:塔克拉玛干 更新时间:2023-11-03 06:03:40 26 4
gpt4 key购买 nike

有没有人设法将 HTML5 样板集成到 YII PHP 框架中(特别是文件夹结构和构建过程)?

最佳答案

Boilerplate 建议在向头部添加样式时使用@import。

<style>@import(/example.css);</style>

Yii使用ClientScript模型添加

<link type="text/css" src="/example.css" />

使用 Yii::app()->clientScript 模型注册文件。 Yii 允许您根据需要为每个 Controller 或每个 View 注册脚本文件。因此您的 http 请求可以是最小的。我建议在主布局中注册所需的脚本/css,并根据需要添加其他脚本

Yii::app()->clientScript->registerScriptFile();

Yii 基于 MVC 模型。 V是为了查看。 View 文件夹包含您的模型和 Controller 将根据数据类型进行调整的 html 元素。在 View 文件夹中,Yii 使用布局文件夹来定义布局。

$this->layout = 'main'; 

该行将查找:

Protected -> views -> layout -> main.php

布局文件夹应包含 main、_htmlHead、_header 和 _footer。 renderPartial 将用于渲染不同的布局部分。这就像 HTML 的 php 包含。 $this->render 或 $this->renderPartial 的第二个参数用于将数据传递给 View 。例如导航数据:

$this->renderPartial('_footer', array('nav'=>array('/link/'=>'Link Name'))); 

在 _htmlHead 中使用 Yii::app()->clientScript 注册所需的元素。如果你想使用不同版本的 jQuery 然后使用 ScriptMap 模型,不要注册 jQuery 两次。 Yii 的 coreScript、验证和分页都是基于 jQuery 的。

$cs = Yii::app()->clientScript;
$cs->registerCssFile('/css/base.css');
$cs->registerScriptFile('/js/base.js', CClientScript::POS_END);
/* Load Script at END of DOM tree: CClientScript::POS_END */

http://www.yiiframework.com/doc/api/1.1/CClientScript

过去我在 Yii 中使用 config.php 文件来设置 assetsLocaion 参数。如果我移动我的 Assets ,它不会破坏网站。

Yii::app()->clientScript->registerScriptFile(Yii::app()->param->assetsLocation.'/js/example.js');

样板的基本布局将在 layout/main.php 中定义。查看主题文档:http://www.yiiframework.com/doc/guide/1.1/en/topics.theming

布局文件可能如下所示:

<!doctype html>
<?php $this->renderPartial('//layouts/_Htmlhead); ?>

<body>

<div id="container">
<?php $this->renderPartial('//layouts/_header); ?>
<div id="main" role="main">
<?php echo $content; ?>
</div>
<?php $this->renderPartial('//layouts/_footer); ?>
</div>
<?php $this->renderPartial('//layouts/_footerScripts); ?>
</body>
</html>

关于php - 带有 Yii 框架的 HTML5Boilerplate,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8929252/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com