批改状态:合格
老师批语:好
<?php
//定义控制器类
class Home{
public function __constructor(){
}
public function index($views,$models){
return $views->views().$models->models();
}
}
//定义视图类
class View{
public function views(){
return '<h2>HI~PHP中文网</h2><p><span>我是学员:';
}
}
//定义模型类
class Model{
public function models(){
return '<b>赵桂福</b>,感谢PHP中文网的每位老师辛苦de付出.</span></p>';
}
}
//根据URL进行业务处理
//本地测试URL是:http://ceshi.com/index2.php/home/index
$path=$_SERVER['PATH_INFO'];
$path=ltrim($path,'/');
$path=explode("/",$path);
//将分拆好的数组进行分别赋值,方便后续使用
$modes=ucfirst($path[0]);
//进行是否为空的判断
if (empty($modes)){
$modes='Home';
}
$func=$path[1];
//进行是否为空的判断
if (empty($func)){
$func='index';
}
echo (new $modes)->$func(new View(),new Model());
?>点击 "运行实例" 按钮查看在线实例
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号