think php 利用反射,调用模型的find方法,失败:
错误提示:
{"code":0,"message":"Method app\model\User::find() does not exist"}
public static function UpdateEntity($modelClass, $pid, $pidValue, $entity) : void
{
$reflection = new ReflectionClass($modelClass);
$method = $reflection->getMethod('find');
$instance = $method->invokeArgs(null, [$pidValue]);
if ($instance)
{
$method = $reflection->getMethod('setAttr');
foreach($entity as $propertyName=>$propertyValue)
{
if ($propertyName == $pid) continue;
$method->invokeArgs($instance, [$propertyName, $propertyValue]);
}
}
$method = $reflection->getMethod('save');
$method->invokeArgs($instance, []);
}