考虑到本文为Joomla开发MVC组件,以下是包含通用模板的代码
$pathToGeneralView = strchr(dirname(__FILE__), dirname($_SERVER['SCRIPT_NAME']));
$pathToGeneralView = str_replace(dirname($_SERVER['SCRIPT_NAME']),'.',$pathToGeneralView );
$pathToGeneralView = $pathToGeneralView . "/../../general/"; <-- returning path from current position.
...
<?php require_once $pathToGeneralView . 'navigate.header.php'; ?>
<P>Do something
<?php require_once $pathToGeneralView . 'navigate.footer.php'; ?>
通过文件系统层次结构,
./com_compname/views/general/navigate.header.php <-- sniplet code for the header
./com_compname/views/general/navigate.footer.php <-- sniplet code for the footer
./com_compname/views/mngtable1/view.html.php
./com_compname/views/mngtable1/tmpl/default.php *
./com_compname/views/mngtable2/view.html.php
./com_compname/views/mngtable2/tmpl/default.php *
既然通用模板组件就在../../general
文件夹下,为什么作者要麻烦使用strchr、str_replace来处理文件夹路径?../../general/navigate.header.php
或../../general/navigate.footer.php
还不够吗?
谢谢。
在joomla中添加路径时,请使用JURI类:
http://docs.joomla.org/JURI/base