沃梦达 / 编程问答 / php问题 / 正文

如何在 Joomla 模板中包含 PHP 函数文件

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

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

问题描述

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

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");

请注意,当硬编码到模板中时,这些功能都可以正常工作,因此肯定是包含的问题.此外,上面的包含路径似乎是正确的,因为如果添加了上面的包含行,模板仍然可以正常工作,除非调用它包含的函数之一.

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.

推荐答案

我已经想通了.我上面的包含路径不正确,即使它没有抛出错误(除非我从包含中调用了一个函数).以下是正确的并且成功地将函数拉入模板中:

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 函数文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本文标题为:如何在 Joomla 模板中包含 PHP 函数文件

基础教程推荐