Answer the question
In order to leave comments, you need to log in
Error in routes ErrorException [ Recoverable Error ]: Object of class Closure could not be converted to string, how to fix?
Hi all.
I can’t understand what the problem is, but I understand why, I threw a piece of routes from the old kohana, and it began to give an error.
ErrorException [ Recoverable Error ]: Object of class Closure could not be converted to string
$expression = preg_replace('#'.Route::REGEX_ESCAPE.'#', '\\\\$0', $uri);
Route:
Route::set(
'page', function ($uri)
{
$db = Database::instance();
$uri_segments = explode('/', $uri);
$product = false;
$alias = $uri_segments[0];
$cat = ORM::factory('page')
->where('alias', '=', $alias)
->find()
->as_array();
if (!empty($cat['id']))
{
if (!isset($uri_segments[1])){
return [
'controller' => 'page',
'action' => 'views',
'directory' => 'index',
'id' => $alias,
'alias' => $alias,
];
}
}
else
{
if (in_array($alias, array("category","product"))){
return false;
}
$alias = $uri_segments[count($uri_segments)-1];
$product = ORM::factory('product')
->where('alias', '=', $alias)
->find();
if ($product->loaded()){
$countSegment = Helper_Tree::getCountCategory($product->category)+1;
if ($countSegment==count($uri_segments)){
return [
'controller' => 'category',
'action' => 'product',
'directory' => 'index',
'id' => $alias,
'alias' => $alias,
];
}else{
return false;
}
}else{
$cat = ORM::factory('category')
->where('alias', '=', $alias)
->find();
if ($cat->loaded()){
$countSegment = Helper_Tree::getCountCategory($cat->parent_id)+1;
if ($countSegment==count($uri_segments)){
return [
'controller' => 'category',
'action' => 'views',
'directory' => 'index',
'id' => $alias,
'alias' => $alias,
];
}else{
return false;
}
}else{
if ((string)intval($alias)==$alias){
//if (count($uri_segments)>1){
$page = $uri_segments[count($uri_segments)-1];
$alias = $uri_segments[count($uri_segments)-2];
return [
'controller' => 'category',
'action' => 'views',
'directory' => 'index',
'id' => $alias,
'alias' => $alias,
'page' => $page
];
//}else{
// return false;
//}
}else{
return false;
}
}
}
}
}
);
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question