[英]PHP OOP & MVC good practice
我正在使用PHP进行解析,在我脑海中一直存在这个问题很长时间,以为我可以自己解决这个问题,但是找不到很好的答案。
例如,这种情况:
我将解析表细分为模型,因此它看起来像这样:
建筑类
class Building extends ParseObject {
public static $parseClassName = "Building";
public static function getCityBuildings($city = null) {
$query = new ParseQuery("Building");
if($city){
$query->equalTo("city", $city);
}
$myBuildings = $query->find();
if(empty($myBuildings)){
return new Building();
}else{
return $myBuildings;
}
}
public static function removeBuilding($objectId){
$query = new ParseQuery("Building");
$Building = $query->get($objectId);
$Building->destroy();
}
}
现在让我们说我有一个需要显示建筑物的PHP页面,但是因为我们不希望用户每次更改城市时都重新加载页面,因此我需要在更改组合框后将AJAX使用到PHP页面。
index.php
//getting some default values.
$myBuildings: Building::getMyBuildings();
<hmtl combobox with default buildings>
<html combobox with cities>
// Imagine some code in where i can AJAX to a php page and change the combobox based on the changed city combobox. passing the chosen city value.
通过AJAX连接该怎么办:
或者,还有另一种方法吗?
关于您提到的第二个选项,对我来说更准确。 但是,我将使用已经解决此问题的框架。 这样您的项目将变得安全。 它增加了与其他人更快地合作的好处,引入了使用该框架的社区测试过的习惯用语和实践……以及更多
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.