mikehaertl / localeurls

Automatic locale/language management for URLs
10 stars 3 forks source link

LocaleUrlManager print out 'controller''controller' before render html why? #6

Open izemize opened 11 years ago

izemize commented 11 years ago

Hy!

LocaleUrlManager print out 'controller''controller' before render html why?

If url is:

http://z3us.sytes.net/videos (error displayed)

If i use this url everything okay:

http://z3us.sytes.net/videos/index


    public function init()
    {
        if($this->getUrlFormat()!==self::PATH_FORMAT)
            throw new CException("LanguageUrlManager only works with urlFormat 'path'");

        return parent::init();
    }
mikehaertl commented 11 years ago

What do you mean by "print out 'controller''controller"? Can you also show your configuration?

izemize commented 11 years ago

My app print 'controller name''controller name' before any controller action.

        'request'=>array(
            'enableCsrfValidation'=>true,
            'csrfTokenName'=>'z3us',
            'enableCookieValidation'=>true,
            'class'=>'ext.localeurls.LocaleHttpRequest',
            'languages'=>array('en','hu','sk','ja'),
        ),
        'urlManager'=>array(
            'class'=>'ext.localeurls.LocaleUrlManager',
            'urlFormat'=>'path',
            'showScriptName'=>false,
            'rules'=>array(
                '<view:\w+>'=>'site/page',
                '<controller:\w+>/<id:\d+>'=>'<controller>/view',
                '<controller:\w+>/<action:\w+>/<id:\d+>'=>'<controller>/<action>',
                '<controller:\w+>/<action:\w+>'=>'<controller>/<action>',
            ),
        ),

halo

mikehaertl commented 11 years ago

I can not see how this could effectively be caused by the extension. I mean, you can go through the code: There's no echo or print anywhere that would output something. Are you sure it's not some debugging code that you forgot to remove?

izemize commented 11 years ago

yes, i'm sure. The part of init (parent::init) prints out this, before any "my" controller action. I'm not sure is this localeHttpRequest bug, maybe yii bug if menu or normalizeUrl not pretty configured. (ex. left action from link)

mikehaertl commented 11 years ago

Can you reproduce this with a clean install using a fresh copy of Yii and my extension? I don't have this problem. And i also don't think it's a Yii bug - it's too obvious and many people would already have complained.

mikehaertl commented 11 years ago

You can also try to hunt it down: Just follow the method calls that are involved and add some die('here'); or something, until the output appears.

Slivicon commented 11 years ago

I believe I saw this (or similar) happen when creating URLs that reference paths under modules. For example, I'm using the Yii User Management module, so for creating a login link in a menu item, the $url is '/user/auth/login'. It seems that when using this extension (which is great btw), take an example we are at the url '/en/user/auth/login', where the 'user' controller is actually coming from 'modules.user.controllers.*' . On this page, a generated "switch language" link to "fr" language appears as '/fr/user/user/auth/login'. A kludge workaround I am using as a temporary workaround is to make sure the passed 'url' $params has a preceding '/':

//code snippet used in layouts/main.php to generate a 'switch language' link which is then passed to the menu used across the top of the page:

$route = $app->controller->route;
$languages = $app->request->languages;
$language = $app->language;
$params = $_GET;
array_unshift($params, $route);
$langLinks = array();
foreach ($languages as $lang) {
    /* we don't want to display a language link
     * for the currently specified language
     */
    if ($lang === $language) {
        continue;
    }
    /* if page is being loaded without a specified language
     * then the app loads the default language: "en_us"
     * and we don't want to display an "English" link
     */
    if ($language == 'en_us' && $lang == 'en') {
        continue;
    }
    $params['language'] = $lang;
    if (isset($params[0]) && $params[0]{1} !== '/') {
        //@todo determine why a preceding '/' is needed for urls that reference modules
        //otherwise the controller part of the url path is repeated
        $cParam = substr($params[0], 0, strpos($params[0], '/'));
        if (isset(Yii::app()->modules) && isset(Yii::app()->modules[$cParam])) {
            //comment the next line to view the "repeated module controller name in the url"
            $params[0] = '/' . $params[0];
            //create static urls to be at the root path
    }
    //$langLinks will be passed as one of an array of menuItems to a 'zii.widgets.CMenu'
    array_push($langLinks, array('label' => $app->params['languageLabels'][$lang], 'url' => $params));
}