1

Is there any Joomla way to return the path or parent's folder path of a current script?

So far when needed, I am using the Joomla Constants and building manually the remaining of the path. It's also possible with php, but I am wondering if there is any Joomla API functionality to get around this.

So let's say I am inside a template override:

templates/mytemplate/html/my_component/my_view/template.php

And want to create a new directory inside the parent "view" directory in order to place a file inside it, like so:

templates/mytemplate/html/my_component/my_view/newDir/newfile.ext

Then I want to call/link that new newFile.ext from the template.php file.

Is there any Joomla way to get the path of my_view dir?

7
  • Can you elaborate your question with more details, your question is broad to understand..
    – Nagarjun
    Commented May 26, 2015 at 16:28
  • @Nagarjun:: sure - I added a simple example.
    – FFrewin
    Commented May 26, 2015 at 16:43
  • I am not sure Joomla way, but you could simply use dirname ( __FILE__ )
    – Nagarjun
    Commented May 26, 2015 at 16:47
  • And to get parent of current directory dirname( dirname(__FILE__) );
    – Nagarjun
    Commented May 26, 2015 at 16:49
  • Dirname is always an option. But wondering if there is any Joomla API functionality. Think there is something similar in WP.
    – FFrewin
    Commented May 26, 2015 at 16:52

1 Answer 1

3

There is no Joomla API to get the current directory. There is no reason for it since dirname(__FILE__) works perfectly fine :-)

If you need to sanitise the filename, you can use JPath::clean().

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.