这是我的控制器
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
,因此要访问CarsModule
内CarsController
内的actionIndex
,您的url应该是localhost/caers/index,而不是localhost/cars/index。如果您不喜欢url像localhost/cars/cars/index,您可以编写一个url管理器规则来将本地主机/汽车/索引映射到本主机/汽车/index>。类似这样的东西:
'cars/index' => 'cars/cars/index'