IndexController.class.php
[PHP] 纯文本查看 复制代码 <?php
namespace Models\Controller;
use Think\Controller;
class IndexController extends Controller {
public function index(){
$this->add('sian');
$this->listUser();
$this->updateUserName(1, 'sian1');
$this->listUser();
$this->deleteUser(1);
$this->listUser();
$this->showUser(1);
}
// 增加一条数据
private function add($username){
$userAttribute = array(
'username' => $username,
);
D('User')->add($userAttribute);
}
// 列出所有数据
private function listUser(){
dump(D('User')->select());
}
// 更新某条数据
private function updateUserName($userId, $userName){
$userAttribute = array(
'id' => $userId,
'username' => $userName,
);
D('User')->save($userAttribute);
}
// 删除某个用户(id)
private function deleteUser($userId){
D('User')->delete($userId);
}
// 显示某个用户(id)
private function showUser($userId){
dump(D('User')->find($userId));
}
}
|