零零零
- 零零零 2019-01-15 已签到连续签到2天,获得了10个金钱
- 零零零 赞了说说周末加班挺好,安静,周一休息挺好,安静~
- 零零零 2019-01-14 已签到连续签到1天,获得了5个金钱
- 零零零 2019-01-12 已签到连续签到1天,获得了5个金钱
在你的
common/config/bootstrap.php
加入这一句试试Yii::setAlias('@components',dirname(dirname(__DIR__)) . '/components');
以下测试:
Yii::setAlias('@test',dirname(dirname(__DIR__)) . '/test');//这是我测试的数据。
test/test.php
文件<?php /** * Created by PhpStorm. * User: Sesame * Date: 2019/1/10 * Time: 10:59 */ namespace test ; class test { public function testAction() { return "测试数据"; } }
在其他控制器调用(在控制器中 use test\test;):
$str = (new test())->testAction(); var_dump($str); die;
打印结果
string(12) "测试数据"
不是很会这个排版。看着有点不舒服,你稍微看仔细点 #笑哭。是这个问题,加入后可以正常访问了,谢谢了大佬!这个bootstrap.php文件,一般多是什么情况下使用,大佬有时间可以给讲一下
- 零零零 赞了回答
在你的
common/config/bootstrap.php
加入这一句试试Yii::setAlias('@components',dirname(dirname(__DIR__)) . '/components');
以下测试:
Yii::setAlias('@test',dirname(dirname(__DIR__)) . '/test');//这是我测试的数据。
test/test.php
文件<?php /** * Created by PhpStorm. * User: Sesame * Date: 2019/1/10 * Time: 10:59 */ namespace test ; class test { public function testAction() { return "测试数据"; } }
在其他控制器调用(在控制器中 use test\test;):
$str = (new test())->testAction(); var_dump($str); die;
打印结果
string(12) "测试数据"
不是很会这个排版。看着有点不舒服,你稍微看仔细点 #笑哭。