【php开源代码栏目提醒】:本文主要为网学会员提供ProductController.php,希望对需要ProductController.php网友有所帮助,学习一下!
<?php
class ProductController extends Core_Controller_Action
{
/**
* 功能:初始化构造函数
*/
public function __construct()
{
if(!$_SESSION['admin'])
{
$this->_redirect('/Index/Login');
}
$this->_model = new ProductModel();
$this->_class = new ClassModel();
$this->_addTmpl = 'ProductAdd.php';
$this->_editTmpl = 'ProductAdd.php';
parent::__construct();
}
/**
* 功能:显示产品列表
*
*/
public function IndexAction()
{
if($_SERVER['REQUEST_METHOD'] == 'POST') //判断是否为提交删除
{
$this->_model->DelProduct($_POST['SelId']);
}
$classid = $this->_getParam('ClassId');
$class = $this->_class->getInfo($classid);
$list = $this->_model->GetProductList($classid);
$path = WEB_DOMAIN . UPLOAD_DIR;
$this->_view->assign('path',$path);
$this->_view->assign('list',$list);
$this->_view->assign('class',$class);
$this->_view->display('ProductList.php');
}
/**
* 功能:显示添加界面
*
*/
public function AddAction()
{
$classid = $this->_getParam('ClassId');
$class = $this->_class->getInfo($classid);
$property = array();
if ($class['F_CLASS_IS_DEFAULT_PROPERTY']) //判断是否显示默认属性
{
$property = $this->_class->GetPropertyList(0);
}else{
if ($class['F_CLASS_IS_PARENT_PROPERTY']) //判断是否继承父属性
{
$property = $this->_class->GetPropertyList($class['F_PARENT_ID']);
}else{
$property = $this->_class->GetPropertyList($class['F_ID']);
}
}
$this->_view->assign('class',$class);
$this->_view->assign('property',$property);
parent::AddAction();
}
/**
* 功能:显示编辑界面
*
*/
public function EditAction()
{
$classid = $this->_getParam('ClassId');
$id = $this->_getParam('Id');
$class = $this->_class->getInfo($classid);
$info = $this->_model->getInfo($id);
$property = array();
if ($class['F_CLASS_IS_DEFAULT_PROPERTY']) //判断是否显示默认属性
{
$property = $this->_class->GetPropertyList(0);
}else{
if ($class['F_CLASS_IS_PARENT_PROPERTY']) //判断是否继承父属性
{
$property = $this->_class->GetPropertyList($class['F_PARENT_ID']);
}else{
$property = $this->_class->GetPropertyList($class['F_ID']);
}
}
$property_value = array();
foreach($property as $key => $value) //循环组合属性值数组
{
$property_value[$key] = $info[$value[F_PROPERTY_FIELDNAME]];
}
$this->_view->assign('class',$class);
$this->_view->assign('property',$property);
$this->_view->assign('property_value',$property_value);
$this->_view->assign('info',$info);
parent::EditAction();
}
/**
* 功能:处理添加数据
*
*/
public function InsertAction()
{
$data = array();
$data[F_ID_CLASS_INFO] = $_POST['classid'];
$data[F_PRODUCT_NAME] = $_POST['name'];
$data[F_PRODUCT_PRICE] = number_format($_POST['price'],2);
$data[F_PRODUCT_LOW_PRICE] = number_format($_POST['low_price'],2);
$data[F_PRODUCT_DESCRIPTION] = htmlspecialchars(addslashes($_POST['content']));
if($_POST['p_id']) //判断是否有属性
{
foreach($_POST['p_id'] as $key => $field) //循环付属性值
{
$data[$field] = $_POST['value'][$key];
}
}
if($this->_model->insert($data)) //判断是否添加成功
{
$this->_redirect('/Product/Index/ClassId/' . $_POST['classid']);
}
}
/**
* 功能:显示编辑输出
*
*/
public function UpdateAction()
{
$data = array();
$data[F_ID_CLASS_INFO] = $_POST['classid'];
$data[F_PRODUCT_NAME] = $_POST['name'];
$data[F_PRODUCT_PRICE] = number_format($_POST['price'],2);
$data[F_PRODUCT_LOW_PRICE] = number_format($_POST['low_price'],2);
$data[F_PRODUCT_DESCRIPTION] = htmlspecialchars(addslashes($_POST['content']));
if($_POST['p_id']) //判断是否有属性
{
foreach($_POST['p_id'] as $key => $field) //循环付属性值
{
$data[$field] = $_POST['value'][$key];
}
}
if($this->_model->update($data,"F_ID = " . $_POST['id'])) //判断是否操作成功
{
$this->_redirect('/Product/Index/ClassId/' . $_POST['classid']);
} else {
$this->_redirect('/Product/Index/ClassId/' . $_POST['classid']);
}
}
/**
* 功能:设置产品顺序
*
*/
public function OrderAction()
{
if($_SERVER['REQUEST_METHOD'] == 'POST') //判断是否提交操作
{
foreach ($_POST['SelId'] as $key => $va