Love Fuel?    Donate

FuelPHP Forums

Ask your question about FuelPHP in the appropriate forum, or help others by answering their questions.
Asset::img et Asset::find_file and local server / online server
  • Hello,

    I develop a website with fulephp.
    In order to display a image i do this : 



    if(Asset::find_file(Config::get('site.logo'), 'img','site/logo/')){
        echo Asset::img('site/logo/'.Config::get('site.logo')); 
    }
    else{
        echo 'no image';
    }


    No problem on my local server, but when i put online, the image is not displayed and there isn't the text "no image".
    The page is called in a folder (not from root). Ex : https://mydomain.com/foo/mypage.php

    In HTML source, there is : <img src="https://mydomain.com/foo/assets/img/image.png">

    But the real path of the image is https://mydomain.com/assets/img/image.png (without the foo).

    In my config file asset.php there is : 'paths' => array('assets/'),

    If I set 'paths' => array('/assets/') to force the root, my message "no image is displayed"



    How does it work ?

    Or from my code ? I don't think because it works on my local server (wamp)
    The error is from my vhost ? Or i did a mistake in a config file ?
    or another thing ?

    thanks
  • How asset works depends on now you configure it. Assuming you have the same folder structure locally and on your server, the result should be the same.

    If you configure "/assets" as your asset path, assets are expected to be in "./public/assets/...". Given your code snippet, it will look for the logo file in "./public/assets/img/site/logo/".

    It might have to do something with the "foo" in your example, indicating you have a non-standard installation?

    So it wlll prrobably depend on what "foo" exactly is, and how you have implemented it (also related to your statement "the page is called in a folder" which I don't understand. Fuel doesn't have pages, it only has an index.php).

  • The problem appears just in my back office which is a module :  https://mydomain.com/admin/

    I don't understand why "admin/" is added when asset is called.

    I tried different stuffs like put always_resolve => true.
    It works for the problem but make lots of other problems (in front office)

    My website works on local server et on staging server but not on production server.
    PHP version was different. After upgrade, the problem is still here, and I don't understand.

    It must be a server problem ... ?

  • Asset doesn't do anything with URL's, it uses the base it is being given when it is instantiated, through the config value 'url'. It also uses the global config value "base_url" to contruct the full URL to the image, so my guess is that that may be wrong.

    Different way of installation? mod_php vs fgci?
    Different location of installation (i.e. in a folder instead of in the docroot)?
    Hardcoded base_url in your config file?

  • I don't know the way of installation.


    I have this in my config asset : 

    'paths' => array('assets/'),

    'img_dir' => 'img/',
    'js_dir' => 'js/',
    'css_dir' => 'css/'
  • URL in the asset config file should be a relative URI, so use "/" when you gave manually configured a base_url in your config.php file, or don't define it at all when your base_url is auto detected.

    Now you've made it into an absolute URL, which makes Asset believe assets are on a different server from your application, something with uses different logic in the Asset class.
  • OK great.

    When I don't define url, the image is displayed but all the other asset (css, js) failed.
    When I define url as '/', it's OK.

    I still don't understand why it worked on local server and not on production server ...

    Thanks.
  • All I can think of is that there is a difference in installation.

Howdy, Stranger!

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

In this Discussion