Love Fuel?    Donate

FuelPHP Forums

Ask your question about FuelPHP in the appropriate forum, or help others by answering their questions.
How does \Uri::current() work?
  • I have 2 controllers.
    1st controller is in fuel/app/classes/controller name test.php
    Test controller have 2 action method name index and aaa

    2nd controller is in fuel/modules/blog/classes/controller/ name blog.php
    Blog controller have 1 action method name installrequired

    Source code in Test controller:
    class Controller_Test extends \Controller_BaseController
    {
       
        public function action_aaa()
        {
            echo 'This is in aaa method.<br>';
            echo '\Uri::main(); = '.\Uri::main() . '<br>';
            echo '\Uri::current(); = '.\Uri::current().'<br>';
        }// action_aaa
       
        public function action_index()
        {
            echo 'current url on main controller: ' . \Uri::main() . '<br>';
            echo Fuel\Core\Request::forge('blog/blog/installrequired')->execute();
            echo '<hr>';
            echo Fuel\Core\Request::forge('test/aaa')->execute();
        }// action_index
    }

    Source code in Blog controller:
    namespace Blog;

    class Controller_Blog extends \Controller_BaseController
    {
        public function action_installrequired()
        {
            echo '\Uri::main(); = '.\Uri::main() . '<br>';
            echo '\Uri::current(); = '.\Uri::current().'<br>';
        }// action_installrequired
    }

    When i call URL http://localhost/installdir/test
    This is my result:
    current url on main controller: http://localhost/installdir/test
    \Uri::main(); = http://localhost/installdir/test
    \Uri::current(); = http://localhost/installdir
    This is in aaa method.
    \Uri::main(); = http://localhost/installdir/test
    \Uri::current(); = http://localhost/installdir

    \Uri::current(); seems to return base url while the document says "The current method allows you to fetch the current URL, including the base URL inside HMVC pattern."

    How does \Uri::current(); really work?
  • After look into fuel/core/classes/uri.php method current().

        /**
         * Gets the current URL, including the BASE_URL
         *
         * @return  string
         */
        public static function current()
        {
            return static::create();
        }

    return static::create(); ????? Hmm?
    The document says about create() "The create method allows you to create a URL with the given URI, including the base URL."
    I'm not sure is this a bug? wrong document description? or something?
    because \Uri::current(); is not "fetch the current URL, including the base URL inside HMVC pattern" as document said.
  • HarroHarro
    Accepted Answer
    There is an issue with the use of Uri::current() in 1.7.1 in relation to HMVC calls (https://github.com/fuel/core/issues/1641), which was fixed recently. If you're not on 1.8/develop, it should be safe to backport the Uri class. Or wait for 1.7.2, which I expect towards the end of the month.

    Your test controller gives me (removed the call to Blog for the test):

    current url on main controller: http://fuel.catwoman.exite.local/18develop/uri

    This is in aaa method.
    \Uri::main(); = http://fuel.catwoman.exite.local/18develop/uri
    \Uri::current(); = http://fuel.catwoman.exite.local/18develop/uri/aaa

Howdy, Stranger!

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

In this Discussion