![](/img/trans.png)
[英]Laravel 5.7 - How to use models & controllers in a custom PHP project?
[英]Alias “custom.controllers.ExampleController.php” is invalid
這是錯誤:
別名“custom.controllers.ExampleController.php”無效。 確保它指向現有的PHP文件,並且該文件是可讀的。
我的代碼如下
main.php=>
return
array(
'controllerMap' => array(
'product' => array(
'class' => 'custom.controllers.Product.php',
),
),
'import' => array(
'custom.mycompany.*',
),
'components' =>
array(
'widgetHandler' => array(
//Load a component
'class' => 'custom.mycompany.mywidget.mywidget',
),
)
);
Product.php=>
<?php
class Product extends Controller
{
public function actionIndex()
{
echo "this is the default index function";
}
public function actionTest()
{
echo "This is the test function";
}
}
我正在使用lightspeed cms。
Yii2 / php類的表示法不是基於點的,而是基於斜線的
'class' => 'custom\controllers\Product.php',
(在你的代碼中沒有ExampleController ..)
見p https://github.com/php-fig/fig-standards/blob/master/accepted/PSR-0.md
和https://github.com/php-fig/fig-standards/blob/master/accepted/PSR-4-autoloader.md
https://github.com/yiisoft/yii2/blob/master/docs/internals/core-code-style.md
對於PHP,Yii2編碼標准建議
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.