【问题标题】:Alias "custom.controllers.ExampleController.php" is invalid别名“custom.controllers.ExampleController.php”无效
【发布时间】:2016-10-26 17:37:54
【问题描述】:

这是错误:

别名“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。

【问题讨论】:

    标签: php yii reference lightspeed


    【解决方案1】:

    Yii2 / php 类的符号不是基于点而是基于斜线

       'class' => 'custom\controllers\Product.php',
    

    (并且在您的代码中没有 ExampleController..)

    见phttps://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 编码标准建议

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-06-11
      • 1970-01-01
      • 1970-01-01
      • 2019-07-12
      相关资源
      最近更新 更多