1 Star 0 Fork 0

web3d / PHPExample

加入 Gitee
与超过 1400万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
demo.php 1.67 KB
一键复制 编辑 原始数据 按行查看 历史
zim 提交于 2016-09-09 23:09 +08:00 . Update demo.php
<?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);
}
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
PHP
1
https://gitee.com/web3d/PHPExample.git
git@gitee.com:web3d/PHPExample.git
web3d
PHPExample
PHPExample
master

搜索帮助