I’m working on a module, and I need the full URL/URI to the modules directory. What is the best way to do this? PATH_MOD is kind of what I need, but I need the URL, not the server path. I feel like there is an easy answer to this, and I could write some PHP to get it, but I wanted to see if there is an EE way to get it.
I came up with this:
$site_url = $PREFS->ini('site_url') ? $PREFS->ini('site_url') . '/' : '';
$this->current_directory = str_replace('//', '/', $site_url . $PREFS->ini('system_folder') . '/modules/redeemer/');But, is site_url ALWAYS defined in every install? It’s been so long since I’ve done a clean out of the box install that I can’t remember. I always have site_url in my config.php file.
I’ve never installed the system directory above root but I know people do it. In those cases I don’t think your method would work.
Why do you need to get the URL path rather than the server path? Are you trying to reference image or stylesheets? If so, you may want to consider putting those in the themes directory and include that instruction in your documentation.
I’m doing an ajax call to a file in my module directory, so I need the absolute URL. Relative URL won’t work.
You bring up a good point too, if the entire module directory is below the root an absolute URL won’t work anyway. Crap.
It’s either I move the file to the themes folder, which is kinda dumb because it isn’t a theme, or I re-write 20 lines of PHP in JavaScript.
You wouldn’t want to call directly to the file anyways. If you need an Ajax call it should be to your modules CP area for security. If the function(s) are not within your mcp.module,php file you should use an include() to still use it there. This way you would use the cp URL to your modules page in your Ajax call.
Hi,
are you guys talking about an Ajax call from the site (module frontend) or Ajax calls within the backend? (the admin doing some admin stuff in mcp.module.php).
I ask because I’m doing the same myself ..
As for getting the URL this is what I’ve come up with for EE 2.0
$vars['_addon_url'] = str_replace('index.php','',$this->EE->config->item('cp_url')) . "expressionengine/third_party/my_modulename/";I’m implementing these editable text-areas (jquery) for the admin. So the javascript will call a method in my mcp.module.php file, but what’s the recommended way of giving a response? Normally if you return “test” you will get a full webpage with all HTML .. doing a die(“test”) will work of course, but it’s superhacky 😉
Packet Tide owns and develops ExpressionEngine. © Packet Tide, All Rights Reserved.