CAKEPHP V3致命误差与自定义路线类别



我正在尝试使用自定义路由类。

有时当我重定向到

之类的URL时
www.site.com/neumaticos-bridgestone 

它返回致命错误。

但是当我刷新页面时,错误是隐藏的

我尝试实现许多自定义路线类

routes.php

$routes->connect('/neumaticos-:marca', ['controller' => 'Pages', 'action' => 'brand'],
     ['routeClass' => 'BrandRoute'])
        ->setPass(['marca']);    
$routes->connect('/neumaticos-para-:slug', ['controller' => 'Pages', 'action' => 'vehicleVersion'],
     ['routeClass' => 'VehicleVersionRoute'])
        ->setPass(['slug']); 

brandroute.php

namespace CakeRoutingRoute;
use CakeUtilityInflector;
use CakeORMTableRegistry;
use CakeORMQuery;

class BrandRoute extends Route
{
    public function parse($url, $method = '')
    {
        $params = parent::parse($url, $method);
        if (!$params) {
            return false;
        }
        //return false;
        $brands = TableRegistry::get('ProductBrands');
        $slug = strtolower($params['marca']);
        $brand = $brands->find()
            ->where([
                'ProductBrands.slug' => $slug
            ])
            ->count();
        if($brand > 0){
            return $params;
        }else{
            return false;
        }
        return false;
    }
}

致命错误是下一个:

Error: CakeRoutingRouteCollection::parseRequest(): The script tried to execute a method or access a property of an incomplete object. Please ensure that the class definition "CakeRoutingRouteBrandRoute" of the object you are trying to operate on was loaded _before_ unserialize() gets called or provide a __autoload() function to load the class definition 
File /var/www/www.site.com/public_html/vendor/cakephp/cakephp/src/Routing/RouteCollection.php 
Line: 205

$ routes-> connect('/:slug',['Controller'=>'cattories','action'=> 'view'],['pass'=> ['slug']](;

,链接将为

$ this-> html-> link($ category-> title,['Controller'=>'类别', 'action'=>'view',$ category-> slug](?>

使用控制器方法将slug文本分为类别和ID等

最新更新