Zend Framework基本页面布局分析

5年以前  |  阅读数:398 次  |  编程语言:PHP 

本文实例讲述了Zend Framework基本页面布局方法。分享给大家供大家参考,具体如下:

Zend Framework 的页面布局模块――Zend_Layout――既可以跟 MVC 一起使用,也可以单独使用。本文只讨论与 MVC 一起使用的情况。

1、布局脚本

在 application/views 下创建一个 layouts 的文件夹。主布局脚本 layout.phtml 代码如下:


    <?php echo $this->doctype('XHTML1_STRICT') ?>
    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <?php echo $this->headTitle() ?>
    <?php
    $this->headLink()->appendStylesheet("/styles/main.css");
    // add more links ...
    ?>
    <?php echo $this->headLink() ?>
    </head>
    <body>
    <div id="header">
    <?php echo $this->partial('header.phtml') ?>
    </div>
    <table>
    <tr>
    <td valign=top>
    <div id="leftcolumn">
    <?php echo $this->partial('leftcolumn.phtml') ?>
    </div>
    </td>
    <td valign=top>
    <div id="content">
    <?php echo $this->layout()->content ?>
    </div>
    </td>
    </tr>
    </table>
    <div id="footer">
    <?php echo $this->partial('footer.phtml') ?>
    </div>
    </body>
    </html>

除了 layout.phtml 之外,还需要编写 header.phtml,leftcolumn.phtml,footer.phtml,以及 main.css 等文件。
Zend Framework 的文档中用一个视图表示了页面布局的应用。

2、设置页面布局

在 MVC 下设置页面布局非常简单,编辑 html/index.php,加入下面两行代码:


    /** Setup layout */
    require_once 'Zend/Layout.php';
    Zend_Layout::startMvc($rootPath . '/application/views/layouts');

注意:在启动页面布局后,要调整已有的各个页面,把不需要的 html 元素,如

<body> 等去掉。另外,可以通过 $this->headTitle() 来设置页面的题头。</p> <p>改变页面的布局也很简单,只需在控制器中用下面的代码即可:</p> <pre><code> $this->_helper->layout->setLayout('new_layout'); </code></pre> <p>如果一个控制器所有动作都使用同一个页面布局,可以通过控制器的初始化函数来设置:</p> <pre><code> public function init() { parent::init(); $this->_helper->layout->setLayout('new_layout'); } </code></pre> <p>更多关于zend相关内容感兴趣的读者可查看本站专题:《<a href="http://www.jb51.net/Special/546.htm">Zend FrameWork框架入门教程</a>》、《<a href="http://www.jb51.net/Special/155.htm">php优秀开发框架总结</a>》、《<a href="http://www.jb51.net/Special/386.htm">Yii框架入门及常用技巧总结</a>》、《<a href="http://www.jb51.net/Special/39.htm">ThinkPHP入门教程</a>》、《<a href="http://www.jb51.net/Special/43.htm">php面向对象程序设计入门教程</a>》、《<a href="http://www.jb51.net/Special/84.htm">php+mysql数据库操作入门教程</a>》及《<a href="http://www.jb51.net/Special/231.htm">php常见数据库操作技巧汇总</a>》</p> <p>希望本文所述对大家基于Zend Framework框架的PHP程序设计有所帮助。</p> <div style="height:30px;"></div> </div> </div> <div class="blockgap"></div> <div class="newcontainer" style="border-radius: 4px;height:90px;overflow:hidden;background:white;"> <div class="row" style="background-color:white;"> <div class="col-md-12 col-xs-12"> <div class="_q1gxh2164d" style="margin-top:10px;margin-bottom:10px;height:90px;background-color:white;"></div> </div> </div> <script type="text/javascript"> (window.slotbydup = window.slotbydup || []).push({ id: "u5897586", container: "_q1gxh2164d", async: true }); </script> </div> <div class="blockgap"></div> <div class="sideblock"> <div class="block-title"><i class="fas fa-chart-line"></i><span> 相关文章:</span></div> <div class="block-body"> <div class="article-entry-content-container"> <div class="article-entry-title-row"> <a target="_blank" class="article-entry-title cleanurl" href="/snippet/view/7413038.html" >PHP分页显示制作详细讲解</a> </div> <div class="article-entry-tag-container"> <span class="cleanurl">PHP</span> <span>  ·  </span> <span class="cleanurl" href="#">发表于 5年以前</span> <span>  ·  </span> <span class="cleanurl" href="#">阅读量:8306</span> </div> </div> <div class="article-entry-content-container"> <div class="article-entry-title-row"> <a target="_blank" class="article-entry-title cleanurl" href="/snippet/view/27214.html" >SSH 登录失败:Host key verification failed</a> </div> <div class="article-entry-tag-container"> <span class="cleanurl">Shell</span> <span>  ·  </span> <span class="cleanurl" href="#">发表于 5年以前</span> <span>  ·  </span> <span class="cleanurl" href="#">阅读量:3358</span> </div> </div> <div class="article-entry-content-container"> <div class="article-entry-title-row"> <a target="_blank" class="article-entry-title cleanurl" href="/snippet/view/57000.html" >获取IMSI</a> </div> <div class="article-entry-tag-container"> <span class="cleanurl">JAVA</span> <span>  ·  </span> <span class="cleanurl" href="#">发表于 5年以前</span> <span>  ·  </span> <span class="cleanurl" href="#">阅读量:3015</span> </div> </div> <div class="article-entry-content-container"> <div class="article-entry-title-row"> <a target="_blank" class="article-entry-title cleanurl" href="/snippet/view/52527.html" >将二进制数据转为16进制以便显示</a> </div> <div class="article-entry-tag-container"> <span class="cleanurl">JAVA</span> <span>  ·  </span> <span class="cleanurl" href="#">发表于 5年以前</span> <span>  ·  </span> <span class="cleanurl" href="#">阅读量:3006</span> </div> </div> <div class="article-entry-content-container"> <div class="article-entry-title-row"> <a target="_blank" class="article-entry-title cleanurl" href="/snippet/view/61716.html" >获取IMEI</a> </div> <div class="article-entry-tag-container"> <span class="cleanurl">JAVA</span> <span>  ·  </span> <span class="cleanurl" href="#">发表于 5年以前</span> <span>  ·  </span> <span class="cleanurl" href="#">阅读量:2844</span> </div> </div> <div class="article-entry-content-container"> <div class="article-entry-title-row"> <a target="_blank" class="article-entry-title cleanurl" href="/snippet/view/2566333858.html" >文件下载</a> </div> <div class="article-entry-tag-container"> <span class="cleanurl">JAVA</span> <span>  ·  </span> <span class="cleanurl" href="#">发表于 5年以前</span> <span>  ·  </span> <span class="cleanurl" href="#">阅读量:2841</span> </div> </div> <div class="article-entry-content-container"> <div class="article-entry-title-row"> <a target="_blank" class="article-entry-title cleanurl" href="/snippet/view/929382096.html" >贪吃蛇</a> </div> <div class="article-entry-tag-container"> <span class="cleanurl">JAVA</span> <span>  ·  </span> <span class="cleanurl" href="#">发表于 5年以前</span> <span>  ·  </span> <span class="cleanurl" href="#">阅读量:2837</span> </div> </div> <div class="article-entry-content-container"> <div class="article-entry-title-row"> <a target="_blank" class="article-entry-title cleanurl" href="/snippet/view/1183891022.html" >双位运算符</a> </div> <div class="article-entry-tag-container"> <span class="cleanurl">JavaScript</span> <span>  ·  </span> <span class="cleanurl" href="#">发表于 4年以前</span> <span>  ·  </span> <span class="cleanurl" href="#">阅读量:2832</span> </div> </div> <div class="article-entry-content-container"> <div class="article-entry-title-row"> <a target="_blank" class="article-entry-title cleanurl" href="/snippet/view/2340236.html" >PHP自定义函数获取搜索引擎来源关键字的方法</a> </div> <div class="article-entry-tag-container"> <span class="cleanurl">PHP</span> <span>  ·  </span> <span class="cleanurl" href="#">发表于 5年以前</span> <span>  ·  </span> <span class="cleanurl" href="#">阅读量:2775</span> </div> </div> <div class="article-entry-content-container"> <div class="article-entry-title-row"> <a target="_blank" class="article-entry-title cleanurl" href="/snippet/view/18848.html" >Java生成UUID</a> </div> <div class="article-entry-tag-container"> <span class="cleanurl">JAVA</span> <span>  ·  </span> <span class="cleanurl" href="#">发表于 5年以前</span> <span>  ·  </span> <span class="cleanurl" href="#">阅读量:2771</span> </div> </div> <div class="article-entry-content-container"> <div class="article-entry-title-row"> <a target="_blank" class="article-entry-title cleanurl" href="/snippet/view/2098383405.html" >发送邮件</a> </div> <div class="article-entry-tag-container"> <span class="cleanurl">Shell</span> <span>  ·  </span> <span class="cleanurl" href="#">发表于 1年以前</span> <span>  ·  </span> <span class="cleanurl" href="#">阅读量:2764</span> </div> </div> <div class="article-entry-content-container"> <div class="article-entry-title-row"> <a target="_blank" class="article-entry-title cleanurl" href="/snippet/view/2978093355.html" >年的日历图</a> </div> <div class="article-entry-tag-container"> <span class="cleanurl">Python</span> <span>  ·  </span> <span class="cleanurl" href="#">发表于 4年以前</span> <span>  ·  </span> <span class="cleanurl" href="#">阅读量:2686</span> </div> </div> <div class="article-entry-content-container"> <div class="article-entry-title-row"> <a target="_blank" class="article-entry-title cleanurl" href="/snippet/view/4215010983.html" >提取后缀名</a> </div> <div class="article-entry-tag-container"> <span class="cleanurl">Python</span> <span>  ·  </span> <span class="cleanurl" href="#">发表于 4年以前</span> <span>  ·  </span> <span class="cleanurl" href="#">阅读量:2675</span> </div> </div> <div class="article-entry-content-container"> <div class="article-entry-title-row"> <a target="_blank" class="article-entry-title cleanurl" href="/snippet/view/7166857.html" >在Zeus Web Server中安装PHP语言支持</a> </div> <div class="article-entry-tag-container"> <span class="cleanurl">PHP</span> <span>  ·  </span> <span class="cleanurl" href="#">发表于 5年以前</span> <span>  ·  </span> <span class="cleanurl" href="#">阅读量:2523</span> </div> </div> <div class="article-entry-content-container"> <div class="article-entry-title-row"> <a target="_blank" class="article-entry-title cleanurl" href="/snippet/view/48950.html" >让你成为最历害的git提交人</a> </div> <div class="article-entry-tag-container"> <span class="cleanurl">Shell</span> <span>  ·  </span> <span class="cleanurl" href="#">发表于 5年以前</span> <span>  ·  </span> <span class="cleanurl" href="#">阅读量:2514</span> </div> </div> <div class="article-entry-content-container"> <div class="article-entry-title-row"> <a target="_blank" class="article-entry-title cleanurl" href="/snippet/view/818909.html" >Yii2汉字转拼音类的实例代码</a> </div> <div class="article-entry-tag-container"> <span class="cleanurl">PHP</span> <span>  ·  </span> <span class="cleanurl" href="#">发表于 5年以前</span> <span>  ·  </span> <span class="cleanurl" href="#">阅读量:2433</span> </div> </div> <div class="article-entry-content-container"> <div class="article-entry-title-row"> <a target="_blank" class="article-entry-title cleanurl" href="/snippet/view/9062154.html" >再谈PHP中单双引号的区别详解</a> </div> <div class="article-entry-tag-container"> <span class="cleanurl">PHP</span> <span>  ·  </span> <span class="cleanurl" href="#">发表于 5年以前</span> <span>  ·  </span> <span class="cleanurl" href="#">阅读量:2429</span> </div> </div> <div class="article-entry-content-container"> <div class="article-entry-title-row"> <a target="_blank" class="article-entry-title cleanurl" href="/snippet/view/83859.html" >指定应用ID以获取对应的应用名称</a> </div> <div class="article-entry-tag-container"> <span class="cleanurl">JAVA</span> <span>  ·  </span> <span class="cleanurl" href="#">发表于 5年以前</span> <span>  ·  </span> <span class="cleanurl" href="#">阅读量:2419</span> </div> </div> <div class="article-entry-content-container"> <div class="article-entry-title-row"> <a target="_blank" class="article-entry-title cleanurl" href="/snippet/view/66475.html" >Python 2与Python 3版本和编码的对比</a> </div> <div class="article-entry-tag-container"> <span class="cleanurl">Python</span> <span>  ·  </span> <span class="cleanurl" href="#">发表于 5年以前</span> <span>  ·  </span> <span class="cleanurl" href="#">阅读量:2396</span> </div> </div> <div class="article-entry-content-container"> <div class="article-entry-title-row"> <a target="_blank" class="article-entry-title cleanurl" href="/snippet/view/4078823.html" >php封装的page分页类完整实例</a> </div> <div class="article-entry-tag-container"> <span class="cleanurl">PHP</span> <span>  ·  </span> <span class="cleanurl" href="#">发表于 5年以前</span> <span>  ·  </span> <span class="cleanurl" href="#">阅读量:2380</span> </div> </div> </div> </div> <div class="blockgap"></div> </div> <div class="three columns"> <div class="sideblock"> <div class="block-title"><i class="fas fa-chart-line"></i><span> 最新文章</span></div> <div class="block-body"> <a class="cleanurl" style="display:block;padding:8px 0px;color:#252933;font-weight:400;word-break: break-word;" href="/snippet/view/1506273484.html"> <div class="snippet_urlblock_title">获取php时间戳</div> <div> <span style="color:#8a919f">4年以前</span> <span style="color:#8a919f"> · </span> <span style="color:#8a919f">731 次阅读</span> </div> </a> <a class="cleanurl" style="display:block;padding:8px 0px;color:#252933;font-weight:400;word-break: break-word;" href="/snippet/view/1044174435.html"> <div class="snippet_urlblock_title">php获取tempfile路径</div> <div> <span style="color:#8a919f">4年以前</span> <span style="color:#8a919f"> · </span> <span style="color:#8a919f">899 次阅读</span> </div> </a> <a class="cleanurl" style="display:block;padding:8px 0px;color:#252933;font-weight:400;word-break: break-word;" href="/snippet/view/330023127.html"> <div class="snippet_urlblock_title">php 1,1,2,3,5,8,13,21,34...求第30位的数是多少?</div> <div> <span style="color:#8a919f">4年以前</span> <span style="color:#8a919f"> · </span> <span style="color:#8a919f">874 次阅读</span> </div> </a> <a class="cleanurl" style="display:block;padding:8px 0px;color:#252933;font-weight:400;word-break: break-word;" href="/snippet/view/3563841287.html"> <div class="snippet_urlblock_title">PHP执行shell</div> <div> <span style="color:#8a919f">4年以前</span> <span style="color:#8a919f"> · </span> <span style="color:#8a919f">875 次阅读</span> </div> </a> <a class="cleanurl" style="display:block;padding:8px 0px;color:#252933;font-weight:400;word-break: break-word;" href="/snippet/view/3073084909.html"> <div class="snippet_urlblock_title">PHP获取HTTP body内容</div> <div> <span style="color:#8a919f">5年以前</span> <span style="color:#8a919f"> · </span> <span style="color:#8a919f">1160 次阅读</span> </div> </a> <a class="cleanurl" style="display:block;padding:8px 0px;color:#252933;font-weight:400;word-break: break-word;" href="/snippet/view/2387064857.html"> <div class="snippet_urlblock_title">php读取目录下的所有文件</div> <div> <span style="color:#8a919f">5年以前</span> <span style="color:#8a919f"> · </span> <span style="color:#8a919f">979 次阅读</span> </div> </a> <a class="cleanurl" style="display:block;padding:8px 0px;color:#252933;font-weight:400;word-break: break-word;" href="/snippet/view/2545869778.html"> <div class="snippet_urlblock_title">php判断是爬虫在访问还是用户浏览器在访问</div> <div> <span style="color:#8a919f">5年以前</span> <span style="color:#8a919f"> · </span> <span style="color:#8a919f">907 次阅读</span> </div> </a> <a class="cleanurl" style="display:block;padding:8px 0px;color:#252933;font-weight:400;word-break: break-word;" href="/snippet/view/3188776308.html"> <div class="snippet_urlblock_title">PHP通过UserAgent识别爬虫</div> <div> <span style="color:#8a919f">5年以前</span> <span style="color:#8a919f"> · </span> <span style="color:#8a919f">999 次阅读</span> </div> </a> <a class="cleanurl" style="display:block;padding:8px 0px;color:#252933;font-weight:400;word-break: break-word;" href="/snippet/view/3825209626.html"> <div class="snippet_urlblock_title">PHP使用curl发起post请求</div> <div> <span style="color:#8a919f">5年以前</span> <span style="color:#8a919f"> · </span> <span style="color:#8a919f">990 次阅读</span> </div> </a> <a class="cleanurl" style="display:block;padding:8px 0px;color:#252933;font-weight:400;word-break: break-word;" href="/snippet/view/3012418925.html"> <div class="snippet_urlblock_title">PHP版HelloWorld</div> <div> <span style="color:#8a919f">5年以前</span> <span style="color:#8a919f"> · </span> <span style="color:#8a919f">823 次阅读</span> </div> </a> </div> </div> <div class="blockgap"></div> <div class="sideblock" style="border-radius: 4px;"> <div class="_d3aes4p30wo" style="width:250px;height:250px;"></div> <script type="text/javascript"> (window.slotbydup = window.slotbydup || []).push({ id: "u1587556", container: "_d3aes4p30wo", async: true }); </script> </div> <div class="blockgap"></div> <div class="sideblock"> <div class="block-title"><i class="fas fa-chart-line"></i><span> 最受欢迎文章</span></div> <div class="block-body"> <a class="cleanurl" style="display:block;padding:8px 0px;color:#252933;font-weight:400;word-break: break-word;" href="/snippet/view/7413038.html"> <div class="snippet_urlblock_title">PHP分页显示制作详细讲解</div> <div> <span style="color:#8a919f">5年以前</span> <span style="color:#8a919f"> · </span> <span style="color:#8a919f">8306 次阅读</span> </div> </a> <a class="cleanurl" style="display:block;padding:8px 0px;color:#252933;font-weight:400;word-break: break-word;" href="/snippet/view/2340236.html"> <div class="snippet_urlblock_title">PHP自定义函数获取搜索引擎来源关键字的方法</div> <div> <span style="color:#8a919f">5年以前</span> <span style="color:#8a919f"> · </span> <span style="color:#8a919f">2775 次阅读</span> </div> </a> <a class="cleanurl" style="display:block;padding:8px 0px;color:#252933;font-weight:400;word-break: break-word;" href="/snippet/view/7166857.html"> <div class="snippet_urlblock_title">在Zeus Web Server中安装PHP语言支持</div> <div> <span style="color:#8a919f">5年以前</span> <span style="color:#8a919f"> · </span> <span style="color:#8a919f">2523 次阅读</span> </div> </a> <a class="cleanurl" style="display:block;padding:8px 0px;color:#252933;font-weight:400;word-break: break-word;" href="/snippet/view/818909.html"> <div class="snippet_urlblock_title">Yii2汉字转拼音类的实例代码</div> <div> <span style="color:#8a919f">5年以前</span> <span style="color:#8a919f"> · </span> <span style="color:#8a919f">2433 次阅读</span> </div> </a> <a class="cleanurl" style="display:block;padding:8px 0px;color:#252933;font-weight:400;word-break: break-word;" href="/snippet/view/9062154.html"> <div class="snippet_urlblock_title">再谈PHP中单双引号的区别详解</div> <div> <span style="color:#8a919f">5年以前</span> <span style="color:#8a919f"> · </span> <span style="color:#8a919f">2429 次阅读</span> </div> </a> <a class="cleanurl" style="display:block;padding:8px 0px;color:#252933;font-weight:400;word-break: break-word;" href="/snippet/view/4078823.html"> <div class="snippet_urlblock_title">php封装的page分页类完整实例</div> <div> <span style="color:#8a919f">5年以前</span> <span style="color:#8a919f"> · </span> <span style="color:#8a919f">2380 次阅读</span> </div> </a> <a class="cleanurl" style="display:block;padding:8px 0px;color:#252933;font-weight:400;word-break: break-word;" href="/snippet/view/2767159.html"> <div class="snippet_urlblock_title">php+ajax+json 详解及实例代码</div> <div> <span style="color:#8a919f">5年以前</span> <span style="color:#8a919f"> · </span> <span style="color:#8a919f">2316 次阅读</span> </div> </a> <a class="cleanurl" style="display:block;padding:8px 0px;color:#252933;font-weight:400;word-break: break-word;" href="/snippet/view/1426374.html"> <div class="snippet_urlblock_title">php数组合并array_merge()函数使用注意事项</div> <div> <span style="color:#8a919f">5年以前</span> <span style="color:#8a919f"> · </span> <span style="color:#8a919f">2286 次阅读</span> </div> </a> <a class="cleanurl" style="display:block;padding:8px 0px;color:#252933;font-weight:400;word-break: break-word;" href="/snippet/view/7069887.html"> <div class="snippet_urlblock_title">PHP设计模式之工厂模式与单例模式</div> <div> <span style="color:#8a919f">5年以前</span> <span style="color:#8a919f"> · </span> <span style="color:#8a919f">2275 次阅读</span> </div> </a> <a class="cleanurl" style="display:block;padding:8px 0px;color:#252933;font-weight:400;word-break: break-word;" href="/snippet/view/1394564.html"> <div class="snippet_urlblock_title">PHP实现简单爬虫的方法</div> <div> <span style="color:#8a919f">5年以前</span> <span style="color:#8a919f"> · </span> <span style="color:#8a919f">2266 次阅读</span> </div> </a> </div> </div> <div class="blockgap"></div> </div> </div> <div ></div> </div> <div class="blockgap"></div> <script src="https://oss-cn-hangzhou.aliyuncs.com/codingsky/cdn1/codingsky/themes/gr/vendor/jquery/dist/jquery.min.js"></script> <script src="https://oss-cn-hangzhou.aliyuncs.com/codingsky/cdn1/codingsky/themes/gr/vendor/jqueryui/jquery-ui-core-widget.min.js"></script> <script src="https://oss-cn-hangzhou.aliyuncs.com/codingsky/cdn1/codingsky/themes/gr/vendor/jqueryui/jquery-ui-core-widget.min.js"></script> <link rel="stylesheet" href="https://oss-cn-hangzhou.aliyuncs.com/codingsky/cdn1/codingsky/themes/gr/v6/css/jquery.tocify.css"> <script src="https://oss-cn-hangzhou.aliyuncs.com/codingsky/cdn1/codingsky/themes/gr/v6/js/jquery.tocify.js"></script> <link rel="stylesheet" href="/themes/gr/toc/toc.css?ver=20231113"> <script src="/themes/gr/toc/toc.js?ver=20231113"></script> <script> var __isIEMode = false; </script> <script src="https://oss-cn-hangzhou.aliyuncs.com/codingsky/cdn1/codingsky/themes/gr/vendor/highlight(11.7)/highlight.min.js"></script> <script src="https://oss-cn-hangzhou.aliyuncs.com/codingsky/cdn1/codingsky/themes/gr/v6/js/lazyload.js"></script> <script src="/themes/gr/js/utils.js?ver=20231113"></script> <script src="https://res.wx.qq.com/open/js/jweixin-1.6.0.js"></script> <script> var snipid = 958569 function onInitSnippetViewPage(){ setElementOnClick("#addlikelink",() => { if(!isLogined()){ window.open("/user/login"); return; } let isLike = getElementAttribute("#addlikelink","isLike"); isLike = isLike == null ? 0 : parseInt(isLike); if(isLike == 0){ snippetBiz.likeSnippet(snipid,function(code,data){ refreshThumbsUpStatus(); }); }else{ snippetBiz.unlikeSnippet(snipid,function(code,data){ refreshThumbsUpStatus(); }); } }); setElementOnClick("#addcollectlink", () => { if(!isLogined()){ window.open("/user/login"); return } let isCollect = getElementAttribute("#addcollectlink","isCollect"); isCollect = isCollect == null ? 0 : parseInt(isCollect); if (isCollect == 0){ snippetBiz.collectSnippet(snipid,function(code,data){ refreshCollectStatus() }) }else{ snippetBiz.removeCollectSnippet(snipid,function(code,data){ refreshCollectStatus() }) } }) function refreshCollectStatus(){ snippetBiz.isCollectSnippet(snipid,function(code,data){ let collectHTML = "<i class=\"fas fa-star\"><div id=\"collectbadge\" class=\"badge\">0</div>"; let uncollectHTML = "<i class=\"far fa-star\"><div id=\"collectbadge\" class=\"badge\">0</div>"; if(code == 200 && data != null && data.code == 0){ if(data.data.is_collected){ setElementInnerHTML("#addcollectlink",collectHTML); setElementAttribute("#addcollectlink","isCollect",1); }else{ setElementInnerHTML("#addcollectlink",uncollectHTML); setElementAttribute("#addcollectlink","isCollect",0); } }else{ setElementInnerHTML("#addcollectlink",uncollectHTML); setElementAttribute("#addcollectlink","isCollect",0); } refreshCollectCount(); }) } function refreshCollectCount(){ snippetBiz.collectSnippetCount(snipid,(code, data) => { if(code == 200 && data != null && data.code == 0){ setElementInnerHTML("#collectbadge",data.data.count); } }); } function refreshThumbsUpStatus(){ snippetBiz.isLikeSnippet(snipid,function(code,data){ let likeHTML = "<i class=\"fas fa-thumbs-up\"><div id=\"likebadge\" class=\"badge\">0</div>"; let unlikeHTML = "<i class=\"far fa-thumbs-up\"><div id=\"likebadge\" class=\"badge\">0</div>"; if(code == 200 && data != null && data.code == 0){ if(data.data.is_liked){ setElementInnerHTML("#addlikelink",likeHTML); setElementAttribute("#addlikelink","isLike",1); }else{ setElementInnerHTML("#addlikelink",unlikeHTML); setElementAttribute("#addlikelink","isLike",0); } }else{ setElementInnerHTML("#addlikelink",likeHTML); setElementAttribute("#addlikelink","isLike",0); } refreshLikeCount(); }) } function refreshLikeCount(){ snippetBiz.likeSnippetCount(snipid,(code, data) => { if(code == 200 && data != null && data.code == 0){ setElementInnerHTML("#likebadge",data.data.count); } }); } refreshCollectStatus(); refreshThumbsUpStatus(); } </script> <script> setTimeout(function(){ var btn = document.getElementById('back-to-top'); if(btn != null){ btn.onclick = function(){ $('body,html').animate({scrollTop:0},300) } } },1000) function initPageAfterCheckToken(){ if(typeof onInitSnippetPage === "function"){ onInitSnippetPage(); } if(typeof onInitSnippetViewPage === "function"){ onInitSnippetViewPage(); } if(typeof onArticlePageLoaded === "function"){ onArticlePageLoaded(); } if(typeof onLoadTocTree === "function"){ onLoadTocTree(); } if(typeof onInitBulmaDialog === "function"){ onInitBulmaDialog(); } } $(document).ready(function(){ initCurrentAuthUser(function(){ if(isLogined()){ $("#login-nav-menu").hide(); //$("#login-nav-menu").text("登录"); //$("#register-nav-menu").hide(); //$("#register-nav-menu").text("注册"); $("#userinfo-nav-menu").show(); $("#username-label").text(getDisplayName()); }else{ $("#login-nav-menu").show(); $("#userinfo-nav-menu").hide(); $("#userinfo-nav-menu-link").hide(); } initPageAfterCheckToken(); }); $('img.lazy').lazyload(); if(typeof wechatShareArticle === "function"){ wechatShareArticle(); } if(__isIEMode){ hljs.initHighlighting(); }else{ hljs.highlightAll(); } if(typeof onInitBookContentPage === "function"){ onInitBookContentPage(); } if(typeof onInitSearchPage === "function"){ onInitSearchPage(); } // 主界面右侧菜单点击 /*$('#userinfo-nav-menu').click(function(){ $("#dropMenuWrapper").toggle(); });*/ }); $(document).click(function(event){ var navMenuIds = ["userinfo-nav-menu","username-label","username-label-caret"] var eventId = $(event.target).attr("id"); var arrIndex = navMenuIds.indexOf(eventId); if(arrIndex >= 0){ return; } $("#dropMenuWrapper").hide(); }); </script> <!-- baidu union --> <script type="text/javascript" src="//cpro.baidustatic.com/cpro/ui/c.js" async="async" defer="defer" ></script> <!-- Global site tag (gtag.js) - Google Analytics <script async src="https://www.googletagmanager.com/gtag/js?id=UA-108792812-1"></script> <script> window.dataLayer = window.dataLayer || []; function gtag(){dataLayer.push(arguments);} gtag('js', new Date()); gtag('config', 'UA-108792812-1'); </script> --> <script> var _hmt = _hmt || []; (function() { var hm = document.createElement("script"); hm.src = "https://hm.baidu.com/hm.js?713c92a31aa12d55b910e2065c7cda9d"; var s = document.getElementsByTagName("script")[0]; s.parentNode.insertBefore(hm, s); })(); </script> <script> /*var _hmt = _hmt || []; (function() { var hm = document.createElement("script"); hm.src = "https://hm.baidu.com/hm.js?e066867ae5a323a82641e57db7e7c914"; var s = document.getElementsByTagName("script")[0]; s.parentNode.insertBefore(hm, s); })();*/ </script> <script> (function(){ var bp = document.createElement('script'); var curProtocol = window.location.protocol.split(':')[0]; if (curProtocol === 'https') { bp.src = 'https://zz.bdstatic.com/linksubmit/push.js'; } else { bp.src = 'http://push.zhanzhang.baidu.com/push.js'; } var s = document.getElementsByTagName("script")[0]; s.parentNode.insertBefore(bp, s); })(); </script> <!-- <script type="text/javascript" src="http://tajs.qq.com/stats?sId=66376258" charset="UTF-8"></script> --> <!-- Google tag (gtag.js) --> <script async src="https://www.googletagmanager.com/gtag/js?id=G-2VE3RBLF6N"></script> <script> window.dataLayer = window.dataLayer || []; function gtag(){dataLayer.push(arguments);} gtag('js', new Date()); gtag('config', 'G-2VE3RBLF6N'); </script> <!-- footer --> <div class="suspension-panel suspension-panel"> <button id="back-to-top" title="回到顶部" class="btn to-top-btn" style=""> <svg width="16" height="16" viewBox="0 0 16 16" fill="none" xmlns="http://www.w3.org/2000/svg" class=""><path data-v-01e634ce="" fill-rule="evenodd" clip-rule="evenodd" d="M2.75 1C2.33579 1 2 1.33579 2 1.75C2 2.16421 2.33579 2.5 2.75 2.5H13.25C13.6642 2.5 14 2.16421 14 1.75C14 1.33579 13.6642 1 13.25 1H2.75ZM7.24407 3.87287C7.64284 3.41241 8.35716 3.41241 8.75593 3.87287L13.0622 8.84535C13.6231 9.49299 13.163 10.5 12.3063 10.5H10V14C10 14.5523 9.55228 15 9 15H7C6.44772 15 6 14.5523 6 14V10.5H3.69371C2.83696 10.5 2.37691 9.49299 2.93778 8.84535L7.24407 3.87287Z" fill="#8A919F"></path></svg> </button> <button title="建议反馈" class="btn meiqia-btn" style=""> <svg width="16" height="16" viewBox="0 0 16 16" fill="none" xmlns="http://www.w3.org/2000/svg" class="icon-feedback"><path data-v-01e634ce="" fill-rule="evenodd" clip-rule="evenodd" d="M1.8252 4.002C1.8252 2.80032 2.79935 1.82617 4.00102 1.82617H12.001C13.2027 1.82617 14.1768 2.80032 14.1768 4.002V9.71628C14.1768 10.918 13.2027 11.8921 12.001 11.8921H9.43308L6.92709 14.1281C6.4455 14.5578 5.68234 14.216 5.68234 13.5706V11.8921H4.00102C2.79934 11.8921 1.8252 10.918 1.8252 9.71628V4.002ZM11.2414 7.86753C11.3826 7.65526 11.3249 7.36878 11.1126 7.22764C10.9004 7.08651 10.6139 7.14417 10.4728 7.35643C9.94042 8.15705 9.03153 8.68309 7.99997 8.68309C6.96841 8.68309 6.05952 8.15705 5.52719 7.35643C5.38605 7.14417 5.09957 7.08651 4.88731 7.22764C4.67504 7.36878 4.61738 7.65526 4.75852 7.86753C5.45467 8.91452 6.64645 9.60617 7.99997 9.60617C9.35349 9.60617 10.5453 8.91452 11.2414 7.86753Z" fill="#1E80FF"></path></svg> </button> </div><footer id="footer" class="footer" style="border-top:1px solid #ccc;background-color:#fff;"> <div class="container" style="margin-top: 10px;"> <div class="row"> <div class="four columns"> <p style="margin-bottom:10px;">网站相关</p> <ul class="sul-list"> <li><a class="cleanurl" href="/about">关于我们 - 理想与情怀,使命与责任</a></li> <li><a class="cleanurl" href="/articles">文章归档 - 您的在线书库</a></li> <li><a class="cleanurl" href="/book">电子书,工具手册</a></li> <li><a class="cleanurl" href="http://weibo.com/codingsky">联系我们 - 新浪微博:哈喽比特</a></li> <li><a class="cleanurl" href="mailto:websitesfeedback@gmail.com">联系我们 - 发送邮件</a></li> </ul> </div> <div class="four columns"> <p style="margin-bottom:10px;">常用链接</p> <ul class="sul-list"> <li><a class="cleanurl" href="https://www.hellokit.com.cn">哈喽工具箱 - 为您提供最好用的软件</a></li> <li><a class="cleanurl" href="https://www.helloandroid.cn/">Android社区 - 在线查看系统原代码</a></li> <li><a class="cleanurl" href="https://www.hellobit.com.cn">哈喽比特 - 汇集优秀技术文章</a></li> <li><a class="cleanurl" href="https://www.flutterchina.net.cn">Flutter中文社区 - Flutter资讯,教程,代码</a></li> </ul> </div> <div class="four columns"> <p style="margin-bottom:10px;">关于</p> <p>我们收集并编写了一些优秀的技术文章。他们或详细的说明某一个技术点,或像百科工具书一样快速的帮您解决手上的问题。</p> </div> </div> <div style="height: 20px;"></div> <div class="row" style="text-align: center"> <span>Copyright© 2013-2023 All Rights Reserved</span> <a style="vertical-align: middle;" href="https://beian.miit.gov.cn">京ICP备2023019179号-8</a> <a style="vertical-align: middle;display:none;" target="_blank" href="http://www.beian.gov.cn/portal/registerSystemInfo?recordcode=11010502044972"><img src="https://oss-cn-hangzhou.aliyuncs.com/codingsky/cdn1/codingsky/images/ga.jpg" style="width:14px;vertical-align: middle;"/>京公网安备 11010502044972号</a> </div> <div style="height: 0px;"></div> </div> </footer> </body> </html>