I was follow i18n tutorial and insert custom language url redirect on top of detect_language method.

Those language url redirect is working when request url like this.

http://localhost -> http://localhost/en

http://localhost/page -> http://localhost/en/page

Now, in my controller. I use HMVC request widget method.

$hmvc = \Request::forge('TestFuelphp/widget', false)->execute();
echo $hmvc;

The FuelPHP works fine without language url redirection but got error 'not redirect properly' when language url redirection was turn on.

If i use HMVC request like this everything works fine.

$hmvc = \Request::forge('en/TestFuelphp/widget', false)->execute();
echo $hmvc;

How to stop redirect in HMVC request?


Source code

class Controller_TestFuelphp extends \Controller
{
    public function action_requestInControllerInApp() 
        {
            echo 'class: ' . __CLASS__ . '<br>'
                . 'method: ' . __FUNCTION__ . '<br>'
                . 'file: ' . __FILE__;
            echo '<hr />';
            echo 'get function arguments:<br /><pre>';

            $args = func_get_args();

            print_r($args);
            echo '</pre>';
            echo '<hr />';
            echo '<h2>Requested hmvc</h2>';

            // $hmvc = \Request::forge('test-fuelphp/widget', false)->execute();
            $hmvc = \Request::forge('TestFuelphp/widget')->execute(); // same result as above.

            echo $hmvc;
        }

    public function action_widget() 
    {
            if (!\Request::is_hmvc()) {
                echo 'This is not hmvc request.';
            } else {
                echo 'class: ' . __CLASS__ . '<br>'
                    . 'method: ' . __FUNCTION__ . '<br>'
                    . 'file: ' . __FILE__;
                echo '<hr />';
                echo 'get function arguments:<br /><pre>';

                $args = func_get_args();

                print_r($args);
                echo '</pre>';
            }
    }
}

fuel/app/classes/controller/testfuelphp.php

有帮助吗?

解决方案

That i18n solution modifies the Uri class. Every request will create it's own instance of Uri, to process the URI passed to it. Which means it will also go through the "detect language" bit for HMVC requests.

This solution isn't very good, and doesn't work (as you have noticed) for HMVC requests.

If you want this type of solution, it's probably better to overload Input::uri(). Call the parent to determine the URI, and upon return check the first segment, and set the locale and strip it if present.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top