以user为例,调用user.php的get_number()方法
一、不管是调用自身模块还是其他模块app\model\User.php写法不变
1 <?php 2 3 namespace app\index\model; 4 use think\Model; 5 6 class user extends Model 7 { 8 public function get_member(){ 9 return 3; 10 } 11 }二、user控制器调用user模块(即控制器调用自身模块)
1 <?php 2 namespace app\index\controller; 3 use think\Db; 4 use think\Controller; 5 use app\index\model\User as Users; 6 class User extends Controller 7 { 8 public function wudi(){ 9 $user = new Users(); 10 $user = $user -> get_member(); 11 echo $user; 12 } 13 }
三、Index控制器调用user模块(即控制器调用其他模块)
<?php namespace app\index\controller; use think\Db; use think\Controller; use app\index\model\User; class Index extends Controller { public function wudi(){ $user = new User(); $user = $user -> get_member(); echo $user; } }四、分析
控制器调用自身模块因为名字都是User,会出现报错。
为了防止这种情况,对User重命名就可以了
重命名语法是(User as 新名字)
(本文为原创文章,转载请注明来自:http://www.cnblogs.com/piaobodewu/)
转载于:https://www.cnblogs.com/piaobodewu/p/9310980.html
相关资源:数据结构—成绩单生成器