Love Fuel?    Donate

FuelPHP Forums

Ask your question about FuelPHP in the appropriate forum, or help others by answering their questions.
Uri::main() execution problem
  • Hi,

    My application executes a same HMVC request on per every page request.

    When I call the HMVC method on the root request (ex. http://mydomain.com/),
    I have got some strange behavior.


    // My HMVC controller
    class Controller_SomeController extends Controller_Base
    {
        function before()
        {
            parent::before();
        }

        public function action_show()
        {
            echo \Uri::main();
            return \Response::forge(\View::forge('twig/widget/myStub.twig');
        }
    }

    Is this correct behavior?

    I'm using FuelPHP v1.7.1

    Sorry for my poor english.

  • Very weird, I' ve never seen that before.

    Uri::main() explicitly uses the uri stored in the main request, i.e. the first request fired.

    Can you check what \Request::main() and \Request::active() return at that point? The first one should return the main request for your root page, the second one the current request (i.e. your widget hmvc call).
  • Thanks for replying to my question.

    Yes, I have checked the pointed out two methods.

    In my HMVC request
    > echo \Request::main()->uri->get() --> ""
    > echo \Request::active()->uri->get() --> "widget/someController/show"

    Expected results.


    By the way I have read through \Uri::create() method which is executed in \Uri::main().

    155> $uri = $uri ?: static::string();

    If $uri equals "" then static::string() is executed.

    133> public static function string()
    134> {
    135>     if ($request = \Request::active())
    136>     {
    137>         return $request->uri->get();
    138>     }
    139>     
    140>     return null;
    141> }

    Since it is called on HMVC context,  above static::string() method returns "widget/someController/show".

    Consequently \Uri::main() method call on HMVC context seems to return "http://mydomain.com/widget/someController/show" on root request.

    Have I misunderstood something?


  • You mean line 155 will take the active URI because the main one is an empty string?

    That would be a bug. Could you create an issue for this at https://github.com/fuel/core/issues so one of the developers can pick it up?
  • Exactly as you say.

    Sure, I reported an issue for this on github.

  • HarroHarro
    Accepted Answer
    Could you try if changing L#155 from

    $uri = $uri ?: static::string();

    to

    is_null($uri) and $uri = static::string();

    and see if that fixes it for you? Then I'll commit it.
  • Yes, I tried your solution and my application problem has been resolved.

    Thank you for your quick correspondence, Harro.

  • Cool, thanks for the feedback.

    I'll double check if this doesn't have any side effects, and if not I will change it for the next release.

Howdy, Stranger!

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

In this Discussion