Jump to content

just a few quick questions.


cssfreakie

Recommended Posts

Hi all, I my hunt for better coding i thought i look at some opensource CMS systems and one thing I saw in the index.php of the joomla cms was this.

 

define('JPATH_BASE', dirname(__FILE__) );
define( 'DS', DIRECTORY_SEPARATOR );

require_once ( JPATH_BASE .DS.'includes'.DS.'defines.php' );
require_once ( JPATH_BASE .DS.'includes'.DS.'framework.php' );

 

Are they using DS to make it work on any platform instead of using a /  or a \  ?

 

Also they define JPATH_BASE,  now they use  dirname(__FILE__) for this. I read that __FILE__ tells from where the script is running. But in that same guide they gave as example dirname(dirname((__FILE__)) instead of only 1 time dirname() That was this website btw: http://www.phpguru.org/php-application-structure

can anyone tell why i would use dirname 2 times and not 1 or 3 or 4?

 

-edit: OK that last question don't needs an answer, i just put loads of dirname() around it and it seems it's moving up in the file system. Leaves my first still open ::)

 

Link to comment
Share on other sites

define( 'DS', DIRECTORY_SEPARATOR );

That line is defining a constant as the value for the PHP system variable DIRECTORY_SEPARATOR. The DIRECTORY_SEPARATOR variable will be a backslash or forwardslash based on the operating system of the server. This ensures that a file path will work whether the application is running on Windows or Linux. They are simply redefining the value as DS as it is much simpler to write DS when you need the directory separator than writing out the full system variable name.

 

Also they define JPATH_BASE,  now they use  dirname(__FILE__) for this. I read that __FILE__ tells from where the script is running. But in that same guide they gave as example dirname(dirname((__FILE__)) instead of only 1 time dirname() That was this website btw: http://www.phpguru.org/php-application-structure

can anyone tell why i would use dirname 2 times and not 1 or 3 or 4?

I see your edit - but if you had really read that page you would understand why two were used. It was kind of the whole point of the article.

Link to comment
Share on other sites

Thanks mate,

 

I think i do understand that last bit, but wasn't clear in telling it. they use dirname 2 times to get above the root of the config where all the other files are. The article is about a save file structure.

 

I never seen that directory separator, but it's great, this topic is solved :)

Cheers and thanks for the quick reply,

 

P.s. topic solved

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.