如何在Joomla模板中包含PHP函数文件 [英] How do I include a file of PHP functions in a Joomla template

查看:190
本文介绍了如何在Joomla模板中包含PHP函数文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直试图在我的模板中包含一个文件,其中包含一些我正打算用于验证成员访问级别的函数,以便为Joomla 2.5中不同类型的用户定制内容。麻烦的是,即使我已经使用了标准的PHP include语句,但这些函数在模板中似乎都没有用。相反调用函数会导致使用该模板的任何页面崩溃。我可以对正在工作的模板顶部的函数进行硬编码,但我也计划在我的Web应用程序的其他地方使用一些函数,因此将它们存储在包含文件中是有意义的。有没有人有一些洞察,为什么函数不能从一个包含,但添加到模板的顶部做?以下是带有include语句的模板的前几行:

I have been trying to include a file in my template which includes some functions I was intending to use for validation of the access level a member has in order to tailor content for different types of users in Joomla 2.5. The trouble is even though I have used the standard PHP include statement, none of the functions appear to be usable in the template. Instead calling the functions causes any pages using the template to crash. I could hard code the functions at the top of the template which is working, but I also have plans to use some the functions elsewhere in my web application, so it makes sense to store them in an include file. Does anyone have some insight into why the functions do not work from an include, but do when added to the top of the template? The following is the top few lines of my template with the include statement:

<?php 
defined( '_JEXEC' ) or die( 'Restricted access' );
JHtml::_('behavior.framework', true);

include ("/includes/checkAccess.php");

请注意,当硬编码到模板中时,所有函数都可以正常工作,所以它肯定是一个问题与包括。另外,上面的include路径看起来是正确的,因为如果添加了上面的include行,模板仍然可以正常工作,除非调用其中包含的某个函数。

Please note the functions all work fine when hard-coded into the template, so it is definitely a problem with the include. Also, the include path above appears to be correct because if the include line above is added, the template still works fine unless a call is made to one of the functions it contains.

推荐答案

我弄明白了。上面的包含路径不正确,即使它没有引发错误(除非我从include调用函数)。以下是正确的,并成功地将函数拉入模板中:

I have figured it out. The include path I had above was not correct even though it wasn't throwing an error (unless I called a function from the include). The following is correct and succeeds in pulling the functions through into the template:

include ("./includes/checkAccess.php");

这篇关于如何在Joomla模板中包含PHP函数文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆