代码拉取完成,页面将自动刷新
<?php
namespace X3D\PHPExample\MathMVC;
class MathController extends Controller
{
public function index()
{
$a = isset($_GET['a']) ? trim($_GET['a']) : null;
$b = isset($_GET['b']) ? trim($_GET['b']) : null;
if (!is_numeric($a) || !is_numeric($b)) { $this->error('无效数据'); }
$model = new Addition($a, $b);
$result = $model->op();
$this->assign('result', $result);
$this->display();
}
}
interface MathInterface
{
public function op();
}
class Addition extends Model implements MathInterface
{
protected $a;
protected $b;
public function __construct(float $a, float $b)
{
$this->setA($a);
$this->setB($b);
}
public function setA(float $a)
{
$this->a = $a;
}
public function setB(float $b)
{
$this->b = $b;
}
public function getA(): $a
{
return $this->a;
}
public function getB($b): float
{
return $this->b;
}
public function op(): float
{
return $a + $b;
}
}
class Model
{
}
class View
{
protected $data = [];
public function assign(string $name, $value)
{
$this->data[$name] = $value;
}
public function render($tplFile)
{
var_dump($data);
Application::end();
}
//......
}
class Controller
{
protected $view = new View;
public function assign($name, $value)
{
$this->view->assign($name, $value);
}
public function display($tplFile)
{
$this->view->render($tplFile);
}
public function error($msg)
{
$this->view->assign('msg', $msg);
$this->view->render('error');
}
}
class Application
{
public static function end(int $code = 0)
{
exit($code);
}
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。