Love Fuel?    Donate

FuelPHP Forums

Ask your question about FuelPHP in the appropriate forum, or help others by answering their questions.
Base URL in Fuel
  • Hi all. Today, I spent the better part of an hour scanning the docs and forum to find the proper way to retrieve the base URL within Fuel. After not finding anything, I devised this solution and placed it in the index.php file within the Public directory:
    // Generate a global variable for the website root
    $fullpath = config::get('base_url');
    $replace = 'public/';
    $newpath = '';
     
    View::set_global('base_path', str_replace($replace, $newpath, $fullpath));
    
    Am I missing something, or does Fuel not have a base url built in? I don't want the unix path, because I would like the root url of the frontend, i.e. http://www.mysite.com/cms. If anyone knows of a better method, let me know. Thanks!
  • I usually do this...
    Uri::create('');
    
  • Paul Boco wrote on Saturday 14th of May 2011:
    I usually do this...
    Uri::create('');
    

    But, can you remove 'public' with the create() method? I was unaware that you could do that.
  • I may not have understood your question. If you are referring to to 'public' directory in the Fuel repo, that is intended to be your document root.
  • He's right, the public directory should be your document root. Provides security and avoids most issues with direct access to your app and core files. Then you can call
    Uri::create('');
    

    to create your url.
  • In the develop branch there a method Uri::base() that does pretty much the same as Uri::create('')
  • Jelmer Schreuder wrote on Sunday 15th of May 2011:
    In the develop branch there a method Uri::base() that does pretty much the same as Uri::create('')

    Ah, thank you. I will check it out. I cannot seem to figure out how to get the URI::create to work, so I'll stick with my method until I can go back and take a closer look at this method.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

In this Discussion