Love Fuel?    Donate

FuelPHP Forums

Ask your question about FuelPHP in the appropriate forum, or help others by answering their questions.
Assets do not work after changing the location of index.php
  • Hello, it's me again. I changed the location of index.php to a sub-folder of public/ and I can't get assets to work this way. But in the index.php file, my DOCROOT still refers to the actuel public folder, like this:
    // DOCROOT = /var/websites/mysite/public
    define('DOCROOT', realpath(__DIR__.'/../../public').DIRECTORY_SEPARATOR);

    I also changed the Config.asset.paths to add the DOCROOT (no /public/ because it's already part of the DOCROOT, like the documentation says:
    'paths' => array(DOCROOT.'assets/'),

    Fuel doesn't throw exceptions about assets not found, but he writes this in my HTML code:
    <link rel="stylesheet" type="text/css" href="http://test.localhost//var/websites/mysite/public/static/cms/css/os.css?1310573600"; />

    It's almost correct, except that the DOCROOT is an absolute path, so we can't just write it in the HML like that. I think DOCROOT has to be stripped when displaying it. I'm using RC3.
  • You have a misunderstanding of what DOCROOT is. DOCROOT is your webservers docroot. And not the folder you decide the index.php should be in. If you move your "application root" to a folder of the docroot, you'll have to modify your rewriting rules, and work with RewriteBase to get your URI paths corrected.
  • Are you talking to me? Or anwsring to nerdsrescueme?
    My DOCROOT is indeed my webservers docroot.
    My index file is not in the DOCROOT.
    My application root is outside of the docroot.
    |+public (my docroot is here)
    |||index.php (symbolic link to website/app/index.php)

    My .htaccess looks like this:
    RewriteRule ^(.*)$ /subfolder/index.php?/$1 [L]

    Changing the Config.assets.paths to prepend the DOCROOT still messes up.
    Maybe the DOCROOT should be removed from the path when the Asset class writes where the asset is?
  • Hi Julian, Can I ask why you have decided to restructure like you have? Phil.
  • I don't see a reply from nerdsrescueme here?
  • Phil Foulston wrote on Wednesday 20th of July 2011:
    I don't see a reply from nerdsrescueme here?
    There was on before... I need this because we're building a CMS on top of Fuel. And the index.php file is never written by the developer but provided by the CMS.
  • You say there's a symlink to the index.php file? I'm not 100% certain, but wouldn't a symbolic link resolve any __DIR__ or __FILE__ calls to the location of the target? If you were so inclined you could alter index.php to use readlink(), but that seems like way too much work. If you're worried about your users having access to the index.php code, perhaps a better solution would be to obfuscate the code... Make it unreadable, therefore, uneditable. If you were going to relocate the file, I wouldn't use a symlink, I would move the file then change the $*_path variables in index.php. From there the remainder of index.php will resolve your paths for you... Then you would have to alter your .htaccess file to rewrite your url's to match. I'm not much good with htaccess, but something LIKE this...
    <IfModule mod_rewrite.c>
        RewriteEngine on
        RewriteCond %{REQUEST_FILENAME} !-f
        RewriteCond %{REQUEST_FILENAME} !-d
        RewriteRule ^(.*)$ [b]website/app/index.php/$1[/b] [L] # CHANGED THIS LINE

    As for your assets, if the asset path is contained in your public folder (Website root) then you could use \Asset::add_path() to add your asset directory from your application and it would look in that folder.
  • Thanks for your help.
    I already did everything you said. Actually the symbolic link has nothing to do with my problem. 1. I move my index.php file into a subfolder of the docroot. That's what matters. 2. I changed the $*_path variables to resolve to the correct directories. 3. I also changed my .htaccess, it works fine, everything gets executed. 4. I changed the Config.assets_path() like the documentation said. It replaces the \Asset::add_path() you're describing. It's the same as \Asset::add_path(DOCROOT.'assets/'); The asset file is found, but the full absolute path gets written in my HTML file, which a problem. I maybe just found a solution.
    I need to extend \Fuel\Core\Fuel to change the generate_base_url() method like this :
    class Fuel extends \Fuel\Core\Fuel {
     protected static function generate_base_url()
      $base_url = parent::generate_base_url();
      // I don't want that subfolder inside my base_url
      return str_replace('subfolder/', '', $base_url);

    I also need to add this little tweak somewhere (index.php, boostrap.php, whatever)

    I DON'T need to change the config.asset_path to use absolute path anymore. This way the file gets searched in the appropriate directory on the file system.
    And is fetched from the right URL by the browser.
    Does it sounds like the good way to solve my issue?
  • If it works it works :) As long as the next upgrade doesn't break it :) but it seems the other steps should have worked without incident.
  • It looks fairly clean to me. Glad you found a way to get this working. After all it's all PHP at the end of the day and whatever works for you is ok. Still it seems like a lot of messing around for something so trivial I still don't really get why you wanted to move it in the first place but you obviously have a requirement that needs to be satisfied.
  • Also when we change the location of index.php it changes the base_url to the path where index.php is.
    I didn't want that it's a bit tricky / unusual. I still want my base_url referring to the docroot (public folder). In the end it's just 4 lines of code so i still can change it easilly!

Howdy, Stranger!

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

In this Discussion