考虑到本文Developing a MVC component for Joomla,以下是包含常规模板的代码
$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
吗?
感谢。