错误的路径如何引导进 action ?
visamz opened this issue · comments
即不在路由表里的错误路径如何引导进指定 action 呢?
其实我觉得 这个问题 应该是问 如何写没有指定的任意访问请求的路由?
比如,我指定了以下路由:
return array(
'/' => 'Quotation\Action\Index',
'/brand' => 'Quotation\Action\Brand'
);
那没有指定的或者说 其它任意请求应该如何写路由~~
现知道要配置到 interceptors 里面,但是如下写法总是报错,求解~~
'viewClass' => array(
'interceptor' => 'TE\Mvc\Action\Interceptor\viewClass',
'params' => array(
'viewClass' => array(
'notFound' => 'Quotation\Action\NotFound'
)
)
)
介样也报错:
'viewClass' => array(
'action' => 'Quotation\Action\NotFound',
'interceptor' => 'TE\Mvc\Action\Interceptor\viewClass',
'params' => array(
'viewClass' => array(
'notFound' => PATH . _THE_
)
)
)
我发现了这个问题,现在定义起来比较麻烦,还要继承一个类,我马上想办法解决
其实你应该在interceptors里定义template,更新后就可以这么用了
'template' => array(
'interceptor' => 'TE\Mvc\Action\Interceptor\Template',
'params' => array(
'path' => ROOT . '/template/',
'notFound' => '404.php',
'error' => '500.php'
)
),
'template' => array(
'interceptor' => 'TE\Mvc\Action\Interceptor\Template',
'params' => array(
'path' => PATH . _THE_,
'notFound' => '404.php',
'error' => '500.php'
)
)
还是报错:
Strict Standards: Declaration of TE\Mvc\View\Error::prepareResponse() should be compatible with that of TE\Mvc\View\Template::prepareResponse() in E:\xampp\htdocs\quotation\system\Mvc\View\Error.php on line 17
而且这样定义的话 就没法 进入 action 了,我希望 notFound 和 error 依然进入指定 action....
理论上介样应该可行的吧。。。
'template' => array(
'interceptor' => 'TE\Mvc\Action\Interceptor\Template',
'params' => array(
'path' => PATH . _THE_
)
),
'viewClass' => array(
'action' => 'Quotation\Action\NotFound',
'interceptor' => 'TE\Mvc\Action\Interceptor\viewClass',
'params' => array(
'notFound' => PATH . _THE_,
)
)
你说的那不是action,是view吧,比如你要对notFound用自己指定的view来处理可以这样
'viewClass' => array(
'action' => 'Quotation\Action\NotFound',
'interceptor' => 'TE\Mvc\Action\Interceptor\viewClass',
'params' => array(
'viewClass' => array(
'notFound' => 'Your\View\Class'
)
)
)
在viewClass这个拦截器里是不能定义路径的,只是用来定义view的缩略名
我想指定 notFound 和 errror 的模板页面,而又想让它像 template 那样能够拦截进入 action,在里面可以反射变量来输出需要的数据该怎么写呢?按你前面写的直接写 404.php 和 500.php 这两个模板页面的话:
'template' => array(
'interceptor' => 'TE\Mvc\Action\Interceptor\Template',
'params' => array(
'path' => ROOT . '/template/',
'notFound' => '404.php',
'error' => '500.php'
)
)
这样无法反射需要的数据变量。