Curlmanager Error "cannot Unset String Offsets"

Hello friends. I have a Yii powered website which run normally on my previous server and even now, runs normally on my local host. But on the server, it displays a blank page. When I turned on "display_errors" in php.ini and set "error_reporting" to "E_ALL", it showed me this error:

When I modified the CUrlManager.php file and added this line to the beginning of createAction method (of course line #285) :


echo '<pre>' . print_r($params, true) . '</pre>' . PHP_EOL;

It displays the following result:

Here is my config/main.php (related parts) :


// enable Yii URL manager

'urlManager'=>array(

    'urlFormat'=>'path',

    'showScriptName'=>false,

    'caseSensitive'=>false,

    'rules'=>array(

        // front-end

        'i-Alert' => 'site/alert',

        'i-Contact' => 'site/contact',

        'i-Departments/<id:\d+>' => 'departments/view',

        'i-Departments' => 'departments/index',

        'i-Experts/<id:\d+>' => 'users/view',

        'i-Experts/<start:[ابپتثجچحخدذرزژسشصضطظعغفقکگلمنوهی]>' => 'users/index',

        'i-Experts' => 'users/index',

        'i-Forgot' => 'users/forgot',

        'i-How' => 'site/how',

        'i-Login' => 'users/login',

        'i-Logout' => 'users/logout',

        'i-Messages' => 'users/messages',

        'i-Portfolio' => 'portfolio/index',

        'i-Projects' => 'projects/index',

        'i-Register' => 'users/register',

        'i-Resume' => 'experts/resume',

        'i-RSS' => 'site/rss',

        'i-Shop/AddProduct/<id:\d+>/<token:\w+>' => 'shop/add',

        'i-Shop/AddProduct/<id:\d+>' => 'shop/add',

        'i-Shop/RemoveProduct/<id:\d+>/<token:\w+>' => 'shop/remove',

        'i-Shop/RemoveProduct/<id:\d+>' => 'shop/remove',

        'i-Shop/EmptyBasket/<token:\w+>' => 'shop/empty',

        'i-Shop/EmptyBasket' => 'shop/empty',

        'i-Shop/Basket' => 'shop/basket',

        'i-Shop/<key:\w+>' => 'shop/index',

        'i-Shop' => 'shop/index',

        'i-StateCities/<id:\d+>' => 'site/cities',

        'i-StateCities' => 'site/cities',

        'i-Update' => 'users/update',

        'i-Terms' => 'site/terms',

    ),

),

I searched a lot for a solution about this problem but to my surprise, nobody even reported it in Yii (in this criteria) and only three links founded and the first one is about Yii (but the problem solved and it’s because of a mistake in the code) and the other two are about wordpress and drupal.

Please let me know why this problem exists and how should I solve it.

Thanks a lot.

I think this is really a bug because Yii should not send strings to the createUrl function. My .htaccess content is:


RewriteEngine on

RewriteCond %{HTTP_HOST} ^***\.***

RewriteRule (.*) http://www.***.***?r=$1 [R=301,L]

RewriteCond %{REQUEST_FILENAME} !-l

RewriteCond %{REQUEST_FILENAME} !-f

RewriteCond %{REQUEST_FILENAME} !-d

RewriteRule . index.php [L,NC,QSA]

I already solved this problem by changing yii/framework/web/CUrlManager.php itself. I changed createUrl function from this:


public function createUrl($route,$params=array(),$ampersand='&')

{

    unset($params[$this->routeVar]);

    foreach($params as $i=>$param)

        if($param===null)

            $params[$i]='';


    if(isset($params['#']))

    {

        $anchor='#'.$params['#'];

        unset($params['#']);

    }

    else

        $anchor='';

    $route=trim($route,'/');

    foreach($this->_rules as $i=>$rule)

    {

        if(is_array($rule))

            $this->_rules[$i]=$rule=Yii::createComponent($rule);

        if(($url=$rule->createUrl($this,$route,$params,$ampersand))!==false)

        {

            if($rule->hasHostInfo)

                return $url==='' ? '/'.$anchor : $url.$anchor;

            else

                return $this->getBaseUrl().'/'.$url.$anchor;

        }

    }

    return $this->createUrlDefault($route,$params,$ampersand).$anchor;

}



To this:


public function createUrl($route,$params=array(),$ampersand='&')

{

    if(is_array($params)) {

        unset($params[$this->routeVar]);

        foreach($params as $i=>$param)

            if($param===null)

                $params[$i]='';


        if(isset($params['#']))

        {

            $anchor='#'.$params['#'];

            unset($params['#']);

        }

        else

            $anchor='';

        $route=trim($route,'/');

        foreach($this->_rules as $i=>$rule)

        {

            if(is_array($rule))

                $this->_rules[$i]=$rule=Yii::createComponent($rule);

            if(($url=$rule->createUrl($this,$route,$params,$ampersand))!==false)

            {

                if($rule->hasHostInfo)

                    return $url==='' ? '/'.$anchor : $url.$anchor;

                else

                    return $this->getBaseUrl().'/'.$url.$anchor;

            }

        }

        return $this->createUrlDefault($route,$params,$ampersand).$anchor;

    }

    return false;

}

And the problem is gone. I don’t now this is solving the problem or just putting an invisibility cloak on it but my problem is solved.

Waiting to hear something from Yii development team.

Hi

I catched the same error. But in my case it was my fall, syntax mistake:


echo CHtml::beginForm($this->createUrl('/question/ask','post'));

instead


echo CHtml::beginForm($this->createUrl('/question/ask'), 'post');

Your solution helped, inspite of I wrote a wrong code. Funny… =)