A
A
Anton2021-04-25 18:26:10
Kohana
Anton, 2021-04-25 18:26:10

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

1 answer(s)
A
Anton, 2021-05-11
Websaytovsky @ws17

I figured it out, I solved the problem, I had to rewrite the entire route, plus update it for a new kohan, this was the problem.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question