Goals: Learning PHP framework, less code in the framework, easy to understand, easy to expand, completely object-oriented,
Novices should practice basic knowledge, especially the operation of arrays, and the MVC pattern, which may be used a lot in the future. Secondly, learning the database well will facilitate the learning of the framework.
The framework actually follows some of the syntax defined by this framework. Extension development, possibly leveraging his architecture, will increase code reuse. Currently the more popular ones are ZF, YII and the domestic THINKPHP, but in the final analysis, the frameworks are all in MVC mode, and you can write them yourself in the future.
Normally I don't speak either. Today I’ll write a code for you to see: Simple Model layer
product.class.php:
class product{
public function getAllProducts(){
$q= "SELECT * FROM Product";
$r=$db->query($q);
$proArr=array();
while($row=db->fetchAssoc($r )){
$proArr[]=$row;
}
return $proArr;
}
}
?>
View and control layer:
getallproducts.php:
$product=new product();
$ps=$product->getAllProducts();
foreach($ps as $p ){
//Output the
found in the database echo $p['name'];
}
This is how I usually write PHP. When programming with arrays,
most of them output SQL statements and nest HTML in the page, which makes the page bloated and difficult to maintain and expand.
It is easier to modify after layering in this way