Love Fuel?    Donate

FuelPHP Forums

Ask your question about FuelPHP in the appropriate forum, or help others by answering their questions.
Bug Tracker : DIRECTORY_SEPARATOR in Asset on windows environment
  • Hi everybody,
    I'm developing in a windows environment and i noticed a bug with Assets.

    I manually instancied an asset instance (assets are not stored within the docroot of the application) :
    \Asset::forge('shared', array('paths' => array('assets/'),
                                            'url' => 'http://shared.mywebsite.com/'));


    In my view :
    echo \Asset::instance('shared')->css(array('bootstrap.css', 'font-awesome.css'));


    Output :
    <link type="text/css" rel="stylesheet" href="http://shared.mywebsite.com/assets\css\bootstrap.css />
    <link type="text/css" rel="stylesheet" href="http://shared.mywebsite.com/assets\css\font-awesome.css />
    i have backslash in url, so files are not loaded. This backslash is the variable 'DS' define in fuel/core/bootstrap.php :
    define('DS', DIRECTORY_SEPARATOR);


    To resolve this problem on windows, I extend the class Asset_Instance and assign the value '/' to the variable 'DS' in the function _unify_path() and it works ! :

    <?php 

    class Asset_Instance extends Fuel\Core\Asset_Instance
    {

        // --------------------------------------------------------------------

        /**
         * Unify the path
         *
         * make sure the directory separator in the path is correct for the
         * platform used, is terminated with a directory separator, and all
         * relative path references are removed
         *
         * @access    private
         * @param    string    The path
         * @param    mixed    Optional directory separator
         * @param    boolean    Optional whether to add trailing directory separator
         * @return    string
         */
        protected function _unify_path($path, $ds = null, $trailing = true)
        {
            //before
            $ds === null and $ds = DS;

            //after
            $ds === null and $ds = '/';

            return rtrim(str_replace(array('\\', '/'), $ds, $path), $ds).($trailing ? $ds : '');
        }

    }

    There is no problem on Linux environment because the constant DIRECTORY_SEPARATOR is a slash /





  • Which version of Fuel are you on?
  • The last : 1.7.3
  • Can you create an issue for this at https://github.com/fuel/core/isssues ?

Howdy, Stranger!

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

In this Discussion