1.在application\index\controller\文件夾裏新建User.phpphp
1 <?php 2 namespace app\index\controller; 3 class User{ 4 public function index(){ 5 return('我是User控制器的index方法'); 6 } 7 }
2.在application\index\controller\文件夾下的Index.php調用User的控制器thinkphp
1 <?php 2 namespace app\index\controller; 3 4 use app\index\controller\User; 5 6 class Index extends Controller 7 { 8 9 public function diaoyong(){ 10 //方法一 11 $model=new \app\index\controller\User; 12 echo $model->index(); 13 echo "______________________<br>"; 14 15 //方法二 16 $model2=new User; 17 echo $model2->index(); 18 echo "______________________<br>"; 19 20 //方法三 21 $model3=controller('User'); 22 echo $model3->index(); 23 24 25 } 26 27 }
3.系統方法通常在tp5\thinkphp\helper.php裏面。app
4.use同名時請使用as。spa