原生php写法
<?php
header("content-type:text/html; charset=utf-8");
//echo ucfirst('a b');
class Student{
private $xh;
private $name;
function hello(){
echo '我的学号是:'.$this->id.'我的名字是:'.$this->name;
}
}
$className = 'Student';
$stu = new $className();
var_dump($stu);
框架写法
/**
* 表名获取动态模型
*
* @param $flag 表名
* @param $param 需要传的数据
* @return mixed|null
*/
public static function getDoMode($flag, $param = [])
{
$src = 'App\Models\people\tsrqxx\\';
$flagBig = ucfirst($flag); //转首字母大写
$name = $src . $flagBig;
if (class_exists($name)) { //判断模型是否存在
$list = new $name($param); //初始化model
return $list;
}
return null;
}
备注
由于是用变量替代表名,框架中不对use 进行识别。所以得用类的全路径;