services.php 中设置di :
$di->set('dispatcher', function () {
$dispatcher = new Dispatcher();
$dispatcher->setDefaultNamespace('Liuxo\Controllers');
return $dispatcher;
});
$di->set('router', function () {
return require __DIR__ . '/routes.php';
});
routes.php 中配置:
$router = new Router();
$router->add("/js/util/ajax/xhr.js",array(
'controller' => 'js',
'action' => 'index'
)); //所知道的只能指向某个控制器
$router->notFound(array('controller'=>'httperr','action'=>'err404'));
return $router;
在浏览器中直接输入http://localhost/pro/js/util/ajax/xhr.js 报错:
JsController handler class cannot be loaded
0 [internal function]: Phalcon\Mvc\Dispatcher->_throwDispatchException('JsController ha...', 2)
1 [internal function]: Phalcon\Dispatcher->dispatch()
2 E:\wwwroot\pro\public\index.php(33): Phalcon\Mvc\Application->handle()
3 {main}
想要js资源通行 该怎样配置路由呢,求高手解答
class JsController extends Controller
{
public function indexAction()
{
}
}
文件名必须是JsController.php
通用js弄个正则表达式就完了^.+\.js$全路由过来
题主是想访问静态资源,直接配置nginx或者apache,如果是静态文件不走phalcon就可以了