Yii Framework Forum: Curlmanager Error "cannot Unset String Offsets" - Yii Framework Forum

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

Curlmanager Error "cannot Unset String Offsets" Rate Topic: -----

#1 User is offline   MLF 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 56
  • Joined: 21-October 13
  • Location:Iran

Posted 12 June 2014 - 03:42 AM

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:

Quote

Fatal error: Cannot unset string offsets in /***/yii/web/CUrlManager.php on line 285


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:

Quote

Array
(
[id] => 1
)

7

Fatal error: Cannot unset string offsets in /***/yii/web/CUrlManager.php on line 286


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.
0

#2 User is offline   MLF 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 56
  • Joined: 21-October 13
  • Location:Iran

Posted 13 June 2014 - 01:24 AM

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.
0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users