Search code examples
phpfunctionjoomlaincludejoomla2.5

How do I include a file of PHP functions in a Joomla template


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.


Solution

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