[英]Unable to resolve the request in Yii using modules
这是我的控制器
class CarsController extends Controller {
public function actionIndex() {
echo 1; exit();
}
}
这是模块文件:
<?php
class CarsModule extends CWebModule {
public $defaultController = "cars";
public function init() {
// this method is called when the module is being created
// you may place code here to customize the module or the application
// import the module-level models and components
$this->setImport(array(
'cars.models.*',
'cars.components.*',
));
}
public function beforeControllerAction($controller, $action) {
if (parent::beforeControllerAction($controller, $action)) {
// this method is called before any module controller action is performed
// you may place customized code here
return true;
}
else
return false;
}
}
我的问题是,如果我访问我的项目,例如:localhost / cars,它可以工作。 如果我访问localhost / cars / index,则会收到此消息: 无法解决请求 。 如果我创建一个新函数并按以下方式访问:localhost / cars / myfunction,则仍然相同。 我在Windows上工作。 有人可以帮我弄这个吗 ?
通常,对于模块的默认URL规则是module/controller/actin
,所以对于接入actionIndex
内CarsController
内CarsModule
,您的网址应为localhost /汽车/汽车/指数 ,不是localhost /汽车/指数 。 如果您不喜欢url像localhost / cars / cars / index ,则可以编写一个URL管理器规则,以将localhost / cars / cars / index映射到localhost / cars / index 。 像这样:
'cars/index' => 'cars/cars/index'
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.