Thinkphp5 classes under the same page cannot be instantiated?
迷茫
迷茫 2017-05-24 11:30:42
0
1
469

When using thinkphp5, on the same page

namespace app\index\model;
    use think\Model;
    // 此处$target='admins';$behaviour='nihao';
    class Firstrow{
        public function mainChoose($target,$behaviour){
            $tableName = $target.'model';
            $openGate = new $tableName();
            return $result = $openGate -> $behaviour();
        }
    }

    class adminsmodel extends Model{
        protected $table = 'admins';
        public function nihao(){
            $result = $this->select()->collection()->toArray();
            return $result;
        }
    }

But the system keeps prompting that the adminsmodel class cannot be found
I suspected that it was a namespace problem, but there was no solution for a while. Could you please answer my questions

迷茫
迷茫

业精于勤,荒于嬉;行成于思,毁于随。

reply all(1)
PHPzhong
正常来说你在另外写个model
然后引用就行
use app/index/mode/adminsmodel;
new adminsmodel;

如果你非要这么任性
使用绝对路径 
new app\index\model\adminsmodel 
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template