[英]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.