Joomla教程中简单的PHP相对路径

时间:2012-03-14 16:40:41

标签: php joomla

考虑到本文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吗?

感谢。

1 个答案:

答案 0 :(得分:1)

在joomla中添加路径时,请使用JURI类:

http://docs.joomla.org/JURI/base