本文整理汇总了PHP中Department::delete方法的典型用法代码示例。如果您正苦于以下问题:PHP Department::delete方法的具体用法?PHP Department::delete怎么用?PHP Department::delete使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Department
的用法示例。
在下文中一共展示了Department::delete方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: delDepartment
/**
* Delete a department from database with the passed ID.
*/
public static function delDepartment($departmentId)
{
$dept = new Department($departmentId);
if ($dept->id == 0) {
// Department wasn't loaded correctly
NQ::simple('intern', INTERN_ERROR, "Error occurred while loading department from database.");
return;
}
$name = $dept->getName();
try {
// Try to delete department.
if (!$dept->delete()) {
// Something bad happend. This should have been caught in the check above...
NQ::simple('intern', INTERN_SUCCESS, "Error occurred deleting department from database.");
return;
}
} catch (Exception $e) {
NQ::simple('intern', INTERN_ERROR, $e->getMessage());
return;
}
// Department deleted successfully.
NQ::simple('intern', INTERN_SUCCESS, "Deleted department <i>{$name}</i>");
}
示例2: Department
function test_delete()
{
//Arrange
$name = "Biology";
$address = "346 Stupid Avenue";
$test_department = new Department($name, $address);
$test_department->save();
$name2 = "Chemiology";
$address2 = "55 Bo Ct";
$test_department2 = new Department($name2, $address2);
$test_department2->save();
//Act
$test_department->delete();
//Assert
$result = Department::getAll();
$this->assertEquals([$test_department2], $result);
}