代码拉取完成,页面将自动刷新
<?php
//引入基础类文件
include 'BaseController.php';
//引入商品处理文件
include 'Service/ProductService.php';
class Product extends Base{
//添加商品
public function addProduct(){
$title = $this->getParameter('title');
$inventory = $this->getParameter('inventory');
$money = $this->getParameter('money');
try {
// 检查是否接收到商品名称和库存
if ($title && $inventory) {
$ProductService=new ProductService();
//查找商品名称是否重复
if($ProductService->getByTitle($account)){
$this->error('商品名称重复');
}
$res=$ProductService->addProduct($title,$inventory,$money);
if(!$res){
$this->error('商品创建失败');
}
// 输出成功消息
$this->success('创建成功',$res);
} else {
// 输出错误消息
$this->error('商品名称和库存不能为空');
}
} catch (PDOException $e) {
// 输出错误消息
$this->error($e->getMessage());
}
}
}
$methodName=$_GET['a'];
$exampleObj = new Product();
$exampleObj->$methodName();
?>
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。