Love Fuel?    Donate

FuelPHP Forums

Ask your question about FuelPHP in the appropriate forum, or help others by answering their questions.
src of inside a view
  • Not sure how to reference an image from a view
    if I use the full url the framework dissects it as class/method/etc etc
    a relative link does not work either.
    any suggestions would be much appreciated.
    thanks
  • As I understand it, requests to your assets are being fed to PHP and routed in Fuel. Is that right? In order for assets to work the webserver should know that the assets directory is static files-only. How you do this depends on the webserver you're using. In nginx, you can simply use try_files like so:
    try_files $uri /index.php;
    
    In Cherokee, simply create a directory rule and assign it the "static content" handler (optionally specify an alternate filesystem path if applicable otherwise leave blank).
  • thanks for the reply. but don't you think the framework has a built in workaround?
    you suggestion will probably get the job done but i dont wanna tinker in server settings just get passed this hurdle....any suggestions as to how to do it via the framework?
    maybe an Html class the Assets class has some way to deal with this issue?
    it should be simple enough to call something like <img />
    or in the case of using an image in inline css also. thanks again for your suggestion
  • You can write an assets controller and have it serve the files instead but I don't recommend it. If you really think you need to do this, all you need to do is route /assets/(:any) to a static file controller. Or route each directory to its own function and have a separate function to actually output the file. I just did this for /assets/img, scrappy! Sorry for the slightly sloppy code, but it seems to work for me =] The route for this would be
    'assets/img/:name' => 'assets/img'
    
  • Sadly i have to report that after much work, it came down to user error.
    here is where I went wrong. : the image src url should not include "public" folder. so for instance the tag would look like this
    <img src="../../assets/img/123.jpg"/>
    Fuel has also this handy function Html::img('path/to/image.png', array("alt" => "Alt Message", class => "myclass")); find out more at http://fuelphp.com/docs/classes/html.html
  • Actually,
    Asset::img('image.png', array('alt' => 'Alt Message', 'class' => 'myclass'));
    

    Read about it here, http://fuelphp.com/docs/classes/asset.html
  • Strange...both Html::img() & Asset::img() look like they do pretty much the same thing. Or did I miss something again?

Howdy, Stranger!

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

In this Discussion