cssfreakie Posted March 1, 2011 Share Posted March 1, 2011 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 Quote Link to comment https://forums.phpfreaks.com/topic/229219-just-a-few-quick-questions/ Share on other sites More sharing options...
Psycho Posted March 1, 2011 Share Posted March 1, 2011 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. Quote Link to comment https://forums.phpfreaks.com/topic/229219-just-a-few-quick-questions/#findComment-1181111 Share on other sites More sharing options...
cssfreakie Posted March 1, 2011 Author Share Posted March 1, 2011 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 Quote Link to comment https://forums.phpfreaks.com/topic/229219-just-a-few-quick-questions/#findComment-1181360 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.