cast()在sql \ mapper中如何做什么?

时间:2017-09-18 11:26:57

标签: php fat-free-framework

我遇到了这段代码片段并与cast()函数混淆了?它做了什么?

    $userModel = new UserModel();
    $record = $userModel->findone(array('id=?', $uid));
    $f3->set('SESSION.deleteUser', $uid);
    $f3->set('user', $record->cast());
    $f3->set('content', 'user/delete.php');
    $template = new \View;
    echo $template->render('dashboard/layout.php');

1 个答案:

答案 0 :(得分:2)

它将{{"演员")Mapper对象转换为关联array

投票前:

$userModel->load(['id=?',123]);
echo $userModel->id; // 123
echo $userModel->name; // John Doe
echo $userModel->country; // Botswana
print_r($userModel); // List of object properties (including inherited)

投射后:

print_r($userModel->cast());
/*
Array
(
    [id] => 123
    [name] => John Doe
    [country] => Botswana
 )
*/

当您想要将映射器的只读副本传递给模板时(#34;关注点分离"),转换非常有用。它还有助于减少内存使用量  加载大量记录时。