我正在观看有关使用OOP的CMS教程 - PHP& RainTPL
当我尝试http://localhost/cms/admin/updateuser.php?id=4
之类的东西时它有ID,所以如果(isset($ _ GET [' id'])&&(int)$ _ GET [' id']> 0)将被执行
但是(else)也执行了,因为它更新了用户!
public function UpdateUser()
{
if(isset($_GET['id']) && (int)$_GET['id']>0)
{
$id = (int)$_GET['id'];
$user = $this->usersModel->GetById($id);
System::Get('tpl')->assign($user);
System::Get('tpl')->draw('updateuser');
}
else
{
if(isset($_POST['UpdateUser']))
{
//Variables
$name = $_POST['name'];
$username = $_POST['username'];
$email = $_POST['email'];
$admin = (int)$_POST['admin'];
$id = (int) $_POST['id'];
//Validation
//array Data
$data = array(
'name' => $name,
'username' => $username,
'email' => $email,
'is_admin' => $admin
);
if($this->usersModel->Update($id,$data))
{
System::Get('tpl')->assign('message','User Updated');
System::Get('tpl')->draw('success');
}
else
{
System::Get('tpl')->assign('message','Error Updating User');
System::Get('tpl')->draw('error');
}
}
else
{
//No Id
System::Get('tpl')->assign('message','NO USER CHOSEN');
System::Get('tpl')->draw('error');
}
}
}
if(isset($_GET['id']) && (int)$_GET['id']>0)
将被执行&还有其他如何同时!!!!
当我尝试这样的事情http://localhost/cms/admin/updateuser.php?id=4
时if语句应该在没有else语句的情况下执行,因为它可以从url获取id
if(isset($_GET['id']) && (int)$_GET['id']>0)
我需要有人解释它是如何运作的?