开发者

Including PHP file in Joomla [closed]

开发者 https://www.devze.com 2023-02-24 12:27 出处:网络
As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references,or expertise, but this question will likely solicit debate, a
As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, argumen开发者_StackOverflow中文版ts, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance. Closed 10 years ago.

I have a logger class that I need to log my application processing. How can I include this file in Joomla, when my file is located in the includes folder. I don't want to always have to include the file using ../../../, because then I have to manually count paths everytime I include my class. Is there any way to generate the line that will include that file relatively?


You could use the Joomla constants for JPath from here: http://docs.joomla.org/JPath like so:

include_once (JPATH_ROOT.DS.'includes'.DS.'some.class.php');

You can replace JPATH_ROOT with any of the following:

JPATH_SITE 
JPATH_BASE 


use this every where

<?php
include $_SERVER['DOCUMENT_ROOT']."/lib/sample.lib.php";
?>


In joomlla 2.5 + never use include_once or require_once to include a class file. PHP has to check if the file has already been loaded before loading the file.

Since joomla 2.5 there is the JLoader::register() method which doesn't use any memory unless you need to execute a method within the class.

http://developer.joomla.org/manual/ch01s04.html

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号