首页 >

yii框架如何访问自定义模块下的controller

php框架|YIIyii框架如何访问自定义模块下的controller
yii,controller
php框架-YII
购物网站的代源码,vscode 游览器,ubuntu etc介绍,tomcat修改日志,sqlite的事务处理,爬虫如何模拟浏览器登陆,wdcp php 5.5,魏县网络营销seo,vod点播网站下载,网站代码开发文档模板lzw
问题:
php源码的网站首页在哪里更改,Ubuntu字体全部乱码,爬虫哈啰app数据,php骑手,seo优化2.4lzw
Site控制器里面的action如何访问?如图:
自动弹窗广告源码,ubuntu看网络速度,怎么绕开爬虫屏蔽,pcel php,seo设置网站lzw
yii框架如何访问自定义模块下的controller

解决方法:

1、建立目录

首先建立如上的目录结构,在api下的以及目录有三个文件夹和一个文件Module.php,这个php文件内容如下:

<?phpnamespace app\modules\api;/** * api module definition class */class Module extends \yii\base\Module{    /**     * @inheritdoc     */    public $controllerNamespace = 'app\modules\api\controllers';    /**     * @inheritdoc     */    public function init()    {        parent::init();        // custom initialization code goes here    }}

(推荐教学:yii框架)

2、web.php

还记得项目根目录下的config文件夹下有个web.php文件么,添加如下字段:

 'basic',    'basePath' => dirname(__DIR__),    'bootstrap' => ['log'],    'aliases' => [        '@bower' => '@vendor/bower-asset',        '@npm'   => '@vendor/npm-asset',    ],    'components' => [        'request' => [            // !!! insert a secret key in the following (if it is empty) - this is required by cookie validation            'cookieValidationKey' => 'jjsYJ_ju0W8ifOv5mY3JBMI6DOppFlo6',        ],        'cache' => [            'class' => 'yii\caching\FileCache',        ],        'user' => [            'identityClass' => 'app\models\User',            'enableAutoLogin' => true,        ],        'errorHandler' => [            'errorAction' => 'site/error',        ],        'mailer' => [            'class' => 'yii\swiftmailer\Mailer',            // send all mails to a file by default. You have to set            // 'useFileTransport' to false and configure a transport            // for the mailer to send real emails.            'useFileTransport' => true,        ],        'log' => [            'traceLevel' => YII_DEBUG ? 3 : 0,            'targets' => [[    'class' => 'yii\log\FileTarget',    'levels' => ['error', 'warning'],],            ],        ],        'db' => $db,        /*        'urlManager' => [            'enablePrettyUrl' => true,            'showScriptName' => false,            'rules' => [            ],        ],        */    ],    'modules' => [        'api' => [            'class' => 'app\modules\api\Module',        ],    ],    'params' => $params,];if (YII_ENV_DEV) {    // configuration adjustments for 'dev' environment    $config['bootstrap'][] = 'debug';    $config['modules']['debug'] = [        'class' => 'yii\debug\Module',        // uncomment the following to add your IP if you are not connecting from localhost.        //'allowedIPs' => ['127.0.0.1', '::1'],    ];    $config['bootstrap'][] = 'gii';    $config['modules']['gii'] = [        'class' => 'yii\gii\Module',        // uncomment the following to add your IP if you are not connecting from localhost.        //'allowedIPs' => ['127.0.0.1', '::1'],    ];}return $config;

3、api组件下的controllers

现在我们在Modules/api/controllers下新建一个SiteControllers.php,内容如下:

<?phpnamespace app\modules\api\controllers;use yii\web\Controller;class SiteController extends Controller{    public function actionIndex()    {        echo "hello world";    }}

4、浏览器访问

最后就是浏览器访问这个actionIndex了,浏览器输入: http://localhost/basic/web/index.php?r=api/site/index

yii框架如何访问自定义模块下的controller

完成!

更多编程相关内容,请关注php中文网编程入门栏目!


yii框架如何访问自定义模块下的controller
  • 比较迷惑的有关问题急需解决!等待高手
  • 比较迷惑的有关问题急需解决!等待高手 | 比较迷惑的有关问题急需解决!等待高手 ...

    yii框架如何访问自定义模块下的controller
  • 关于zend.framework的一些疑问解决办法
  • 关于zend.framework的一些疑问解决办法 | 关于zend.framework的一些疑问解决办法 ...

    yii框架如何访问自定义模块下的controller
  • php的基础架构MVC
  • php的基础架构MVC | php的基础架构MVC ...