OpenCart之解讀商品管理

因?yàn)楣纠镒錾坛情_發(fā)用的是OpenCart,上級(jí)讓我先熟悉這個(gè)系統(tǒng),借此機(jī)會(huì)詳細(xì)解讀一下商品管理這一功能(也是為了日后給自己加深印象)。

首先,單擊商品管理進(jìn)入商品列表后,像這樣:

商品列表界面


上面的六個(gè)文本是用來篩選的,下面的商品列表是用來排序的;所以一個(gè)完整的url可能會(huì)包括(token:密鑰,filter_name:商品名稱,filter_model:商品型號(hào),filter_price:銷售價(jià)格,filter_quantity:商品數(shù)量,filter_status:狀態(tài),filter_category:分類,sort則為按: (商品名稱,商品型號(hào),價(jià)格,數(shù)量,狀態(tài))來排序,order:(DESC,ASC),page:分頁);


上面的panel是用來篩選條件的,像 分頁,如圖六個(gè)字段,都是通過字段名加在url后面作為參數(shù)傳遞的;因此,只要商品信息有變化,就要像這樣:

$url = '';

if (isset($this->request->get['filter_name'])) {

? $url .= '&filter_name=' . urlencode(html_entity_decode($this->request->get['filter_name'], ENT_QUOTES, 'UTF-8'));

}

if (isset($this->request->get['filter_model'])) {

? $url .= '&filter_model=' . urlencode(html_entity_decode($this->request->get['filter_model'], ENT_QUOTES, 'UTF-8'));

}

if (isset($this->request->get['filter_price'])) {

? $url .= '&filter_price=' . $this->request->get['filter_price'];

}

if (isset($this->request->get['filter_quantity'])) {

? $url .= '&filter_quantity=' . $this->request->get['filter_quantity'];

}

? ? ? if (isset($this->request->get['filter_category'])) {

? ? ? ? ? $url .= '&filter_category=' . $this->request->get['filter_category'];

? ? ? }

? ? ? if (isset($this->request->get['filter_status'])) {

? $url .= '&filter_status=' . $this->request->get['filter_status'];

}

if (isset($this->request->get['sort'])) {

? $url .= '&sort=' . $this->request->get['sort'];

}

if (isset($this->request->get['order'])) {

? $url .= '&order=' . $this->request->get['order'];

}

if (isset($this->request->get['page'])) {

? $url .= '&page=' . $this->request->get['page'];

}

因?yàn)闀?huì)刷新頁面,所以要重新組織url及url后面的參數(shù),這樣就可以:刪除某些數(shù)量商品后,還能夠保持在原有的頁數(shù)上,或是原來的篩選條件上;

在點(diǎn)了篩選按鈕后,商品列表的首頁中的js代碼首先會(huì)獲取到你在上圖六個(gè)文本中填寫的內(nèi)容,然后拼接到url上去,再location跳轉(zhuǎn)到url(其實(shí)還是商品列表首頁,只不過帶著篩選條件);

<script type="text/javascript">

$('#button-filter').on('click', function() {

? var url = 'index.php?route=catalog/product&token=<?php echo $token; ?>';

? var filter_name = $('input[name=\'filter_name\']').val();

? if (filter_name) {

? ? ? url += '&filter_name=' + encodeURIComponent(filter_name);

? }

? var filter_model = $('input[name=\'filter_model\']').val();

? if (filter_model) {

? ? ? url += '&filter_model=' + encodeURIComponent(filter_model);

? }

? var filter_price = $('input[name=\'filter_price\']').val();

? if (filter_price) {

? ? ? url += '&filter_price=' + encodeURIComponent(filter_price);

? }

? var filter_quantity = $('input[name=\'filter_quantity\']').val();

? if (filter_quantity) {

? ? ? url += '&filter_quantity=' + encodeURIComponent(filter_quantity);

? }

? var filter_status = $('select[name=\'filter_status\']').val();

? if (filter_status != '*') {

? ? ? url += '&filter_status=' + encodeURIComponent(filter_status);

? }

? ? var filter_category = $('select[name=\'filter_category\']').val();

? ? if (filter_category != '*') {

? ? ? ? url += '&filter_category=' + encodeURIComponent(filter_category);

? ? }

? location = url;

});

</script>


在跳轉(zhuǎn)頁面后,重新調(diào)用controller中的index方法加載(這里調(diào)用的getList()方法功能大概可理解為:按條件篩選遍歷獲取所有商品,加載首頁商品列表的視圖);

public function index() {

? $this->language->load('catalog/product');

? $this->document->setTitle($this->language->get('heading_title'));

? $this->load->model('catalog/product');

? $this->getList();

}

這里index中的意義為:加載語言包,設(shè)置title標(biāo)題,最重要的是先載入要進(jìn)行操作數(shù)據(jù)庫的model,再調(diào)用同controller中的getList()方法;由于controller中的getList()方法內(nèi)容實(shí)在太多,但我就要一一講解一下:)


? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?-- Start getList() --

首先,(是否點(diǎn)擊了篩選按鈕)先查看是否存在篩選條件:(不存在只要設(shè)為null即可);

if (isset($this->request->get['filter_name'])) {

? $filter_name = $this->request->get['filter_name'];

} else {

? $filter_name = null;

}

if (isset($this->request->get['filter_model'])) {

? $filter_model = $this->request->get['filter_model'];

} else {

? $filter_model = null;

}

if (isset($this->request->get['filter_price'])) {

? $filter_price = $this->request->get['filter_price'];

} else {

? $filter_price = null;

}

if (isset($this->request->get['filter_quantity'])) {

? $filter_quantity = $this->request->get['filter_quantity'];

} else {

? $filter_quantity = null;

}

if (isset($this->request->get['filter_status'])) {

? $filter_status = $this->request->get['filter_status'];

} else {

? $filter_status = null;

}

? ? ? if (isset($this->request->get['filter_category'])) {

? ? ? ? ? $filter_category = $this->request->get['filter_category'];

? ? ? } else {

? ? ? ? ? $filter_category = null;

? ? ? }

其次,(是否點(diǎn)擊了商品列表的標(biāo)題欄排序)再查看是否有排序條件:(這里默認(rèn)為按商品名稱ASC排序,第一頁);

if (isset($this->request->get['sort'])) {

? $sort = $this->request->get['sort'];

} else {

? $sort = 'pd.name';

}

if (isset($this->request->get['order'])) {

? $order = $this->request->get['order'];

} else {

? $order = 'ASC';

}

if (isset($this->request->get['page'])) {

? $page = $this->request->get['page'];

} else {

? $page = 1;

}

有了各字段后,再進(jìn)行組織url:

$url = '';

if (isset($this->request->get['filter_name'])) {

? $url .= '&filter_name=' . urlencode(html_entity_decode($this->request->get['filter_name'], ENT_QUOTES, 'UTF-8'));

}

if (isset($this->request->get['filter_model'])) {

? $url .= '&filter_model=' . urlencode(html_entity_decode($this->request->get['filter_model'], ENT_QUOTES, 'UTF-8'));

}

if (isset($this->request->get['filter_price'])) {

? $url .= '&filter_price=' . $this->request->get['filter_price'];

}

if (isset($this->request->get['filter_quantity'])) {

? $url .= '&filter_quantity=' . $this->request->get['filter_quantity'];

}

if (isset($this->request->get['filter_category'])) {

? ?$url .= '&filter_category=' . $this->request->get['filter_category'];

}

if (isset($this->request->get['filter_status'])) {

? $url .= '&filter_status=' . $this->request->get['filter_status'];

}

if (isset($this->request->get['sort'])) {

? $url .= '&sort=' . $this->request->get['sort'];

}

if (isset($this->request->get['order'])) {

? $url .= '&order=' . $this->request->get['order'];

}

if (isset($this->request->get['page'])) {

? $url .= '&page=' . $this->request->get['page'];

}

// urlencode():此函數(shù)便于將字符串編碼并將其用于 URL 的請(qǐng)求部分,同時(shí)它還便于將變量傳遞給下一頁。

// html_entity_decode():此函數(shù)把 HTML 實(shí)體轉(zhuǎn)換為字符。

完成之后我們就得到了一個(gè)完整的url;

接下來是面包屑導(dǎo)航:

$data['breadcrumbs'] = array();

$data['breadcrumbs'][] = array(

? 'text' => $this->language->get('text_home'),

? 'href' => $this->url->link('common/dashboard', 'token=' . $this->session->data['token'], 'SSL')

);

$data['breadcrumbs'][] = array(

? 'text' => $this->language->get('heading_title'),

? 'href' => $this->url->link('catalog/product', 'token=' . $this->session->data['token'] . $url, 'SSL')

);

再是三個(gè)按鈕:新增商品,復(fù)制商品和刪除商品(這個(gè)我們稍后再講);

$data['add'] = $this->url->link('catalog/product/add', 'token=' . $this->session->data['token'] . $url, 'SSL'); ? ? ? ? ? ? ? //新增商品

$data['copy'] = $this->url->link('catalog/product/copy', 'token=' . $this->session->data['token'] . $url, 'SSL'); ? ? ? ? ? ? //復(fù)制商品

$data['delete'] = $this->url->link('catalog/product/delete', 'token=' . $this->session->data['token'] . $url, 'SSL'); ? ? ? ? //刪除商品

再是從request中獲取到的篩選條件:

$filter_data = array(

? 'filter_name' ? ?=> $filter_name, ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?//商品名稱

? 'filter_model' ?=> $filter_model, ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?//商品型號(hào)

? 'filter_price' ?=> $filter_price, ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?//銷售價(jià)格

? 'filter_quantity' => $filter_quantity, ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? //商品數(shù)量

? 'filter_status' ?=> $filter_status, ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?//狀態(tài)

? 'filter_category' => $filter_category, ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? //分類

? 'filter_is_limit' => 0, ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?//商品是啟用還是停用

? 'sort' ? ? ? ? ? ?=> $sort, ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?//排序的字段

? 'order' ? ? ? ? ?=> $order, ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?//ASC還是DESC

? 'start' ? ? ? ? ?=> ($page - 1) * $this->config->get('config_limit_admin'), ? ? ? ?//開始的頁數(shù)

? 'limit' ? ? ? ? ?=> $this->config->get('config_limit_admin') ? ? ? ? ? ? ? ? ? ? ? //配置文件中,一頁多少條記錄

);

然后再通過向model模型傳遞$filter_data篩選條件來獲取:符合條件的商品數(shù)量:$product_total,符合條件的商品信息:$results

model_catalog_product文件中以下兩個(gè)方法都是把篩選數(shù)據(jù)傳遞過去,然后相應(yīng)的改變sql語句即可;

$product_total = $this->model_catalog_product->getTotalProducts($filter_data);

$results = $this->model_catalog_product->getProducts($filter_data);

再是組織商品的信息:

$data['products'] = array();

foreach ($results as $result) {

? //這之前要先$this->load->model('tool/image')加載工具類(只是調(diào)整了圖片的大小)

? if (is_file(DIR_IMAGE . $result['image'])) {

? ? ? $image = $this->model_tool_image->resize($result['image'], 40, 40);

? } else {

? ? ? $image = $this->model_tool_image->resize('no_image.png', 40, 40);

? }

? /********這里特惠商品,暫時(shí)不做介紹**********/

? $special = false;

? $product_specials = $this->model_catalog_product->getProductSpecials($result['product_id']);

? foreach ($product_specials ?as $product_special) {

? ? ? if (($product_special['date_start'] == '0000-00-00' || strtotime($product_special['date_start']) < time()) && ($product_special['date_end'] == '0000-00-00' || strtotime($product_special['date_end']) > time())) {

? ? ? ? $special = $product_special['price'];

? ? ? ? break;

? ? ? }

? }

? /********這里特惠商品,暫時(shí)不做介紹**********/

? //重新整理組織商品信息

? $data['products'][] = array(

? ? ? 'product_id' => $result['product_id'],

? ? ? 'image' ? ? ?=> $image,

? ? ? 'name' ? ? ?=> $result['name'],

? ? ? 'model' ? ? ?=> $result['model'],

? ? ? 'price' ? ? ?=> $result['price'],

? ? ? 'special' ? ?=> $special,

? ? ? 'quantity' ?=> $result['quantity'],

? ? ? 'status' ? ?=> ($result['status']) ? $this->language->get('text_enabled') : $this->language->get('text_disabled'),

? ? ? 'edit' ? ? ?=> $this->url->link('catalog/product/edit', 'token=' . $this->session->data['token'] . '&product_id=' . $result['product_id'] . $url, 'SSL'), ? ? ? ? ? //編輯商品

? ? ? 'add_limit' ?=> $this->url->link('catalog/product_limit/add', 'token=' . $this->session->data['token'] . '&product_id=' . $result['product_id'] . $url, 'SSL'),

? );

}

$data['token'] = $this->session->data['token']; ? ? ? ? ?//從session中獲取token的值

再給商品列表中的五個(gè)標(biāo)題添加鏈接(就是配置相應(yīng)的url,使得能有排序的功能):

$url = '';

if (isset($this->request->get['filter_name'])) {

? $url .= '&filter_name=' . urlencode(html_entity_decode($this->request->get['filter_name'], ENT_QUOTES, 'UTF-8'));

}

if (isset($this->request->get['filter_model'])) {

? $url .= '&filter_model=' . urlencode(html_entity_decode($this->request->get['filter_model'], ENT_QUOTES, 'UTF-8'));

}

if (isset($this->request->get['filter_price'])) {

? $url .= '&filter_price=' . $this->request->get['filter_price'];

}

? ? ? if (isset($this->request->get['filter_category'])) {

? ? ? ? ? $url .= '&filter_category=' . $this->request->get['filter_category'];

? ? ? }

if (isset($this->request->get['filter_quantity'])) {

? $url .= '&filter_quantity=' . $this->request->get['filter_quantity'];

}

if (isset($this->request->get['filter_status'])) {

? $url .= '&filter_status=' . $this->request->get['filter_status'];

}

if ($order == 'ASC') {

? $url .= '&order=DESC';

} else {

? $url .= '&order=ASC';

}

if (isset($this->request->get['page'])) {

? $url .= '&page=' . $this->request->get['page'];

}

$data['sort_name'] = $this->url->link('catalog/product', 'token=' . $this->session->data['token'] . '&sort=pd.name' . $url, 'SSL');

$data['sort_model'] = $this->url->link('catalog/product', 'token=' . $this->session->data['token'] . '&sort=p.model' . $url, 'SSL');

$data['sort_price'] = $this->url->link('catalog/product', 'token=' . $this->session->data['token'] . '&sort=p.price' . $url, 'SSL');

$data['sort_quantity'] = $this->url->link('catalog/product', 'token=' . $this->session->data['token'] . '&sort=p.quantity' . $url, 'SSL');

$data['sort_status'] = $this->url->link('catalog/product', 'token=' . $this->session->data['token'] . '&sort=p.status' . $url, 'SSL');

$data['sort_order'] = $this->url->link('catalog/product', 'token=' . $this->session->data['token'] . '&sort=p.sort_order' . $url, 'SSL');

再配置分頁功能:(配置一次就要重新組織一次url)

$url = '';

if (isset($this->request->get['filter_name'])) {

? $url .= '&filter_name=' . urlencode(html_entity_decode($this->request->get['filter_name'], ENT_QUOTES, 'UTF-8'));

}

if (isset($this->request->get['filter_model'])) {

? $url .= '&filter_model=' . urlencode(html_entity_decode($this->request->get['filter_model'], ENT_QUOTES, 'UTF-8'));

}

if (isset($this->request->get['filter_price'])) {

? $url .= '&filter_price=' . $this->request->get['filter_price'];

}

if (isset($this->request->get['filter_quantity'])) {

? $url .= '&filter_quantity=' . $this->request->get['filter_quantity'];

}

? ? ? if (isset($this->request->get['filter_category'])) {

? ? ? ? ? $url .= '&filter_category=' . $this->request->get['filter_category'];

? ? ? }

if (isset($this->request->get['filter_status'])) {

? $url .= '&filter_status=' . $this->request->get['filter_status'];

}

if (isset($this->request->get['sort'])) {

? $url .= '&sort=' . $this->request->get['sort'];

}

if (isset($this->request->get['order'])) {

? $url .= '&order=' . $this->request->get['order'];

}

$pagination = new Pagination();

$pagination->total = $product_total;

$pagination->page = $page;

$pagination->limit = $this->config->get('config_limit_admin');

$pagination->url = $this->url->link('catalog/product', 'token=' . $this->session->data['token'] . $url . '&page={page}', 'SSL');

$data['pagination'] = $pagination->render(); ? ? ? ? ? ? ? //這個(gè)是分頁

$data['results'] = sprintf($this->language->get('text_pagination'), ($product_total) ? (($page - 1) * $this->config->get('config_limit_admin')) + 1 : 0, ((($page - 1) * $this->config->get('config_limit_admin')) > ($product_total - $this->config->get('config_limit_admin'))) ? $product_total : ((($page - 1) * $this->config->get('config_limit_admin')) + $this->config->get('config_limit_admin')), $product_total, ceil($product_total / $this->config->get('config_limit_admin'))); ? ? ? ? ?//這個(gè)是分頁的信息

最后再傳遞數(shù)據(jù):

/*****************若有篩選信息,則傳遞到視圖的文本框中******************/

$data['filter_name'] = $filter_name;

$data['filter_model'] = $filter_model;

$data['filter_price'] = $filter_price;

$data['filter_quantity'] = $filter_quantity;

$data['filter_status'] = $filter_status;

$data['filter_category'] = $filter_category;

/********傳遞排序的信息過去,在視圖頁面進(jìn)行判斷*********/

$data['sort'] = $sort;

$data['order'] = $order;

$data['header'] = $this->load->controller('common/header');

$data['column_left'] = $this->load->controller('common/column_left');

$data['footer'] = $this->load->controller('common/footer');

//加載視圖,傳遞數(shù)據(jù)

$this->response->setOutput($this->load->view('catalog/product_list.tpl', $data));

? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?-- END getList() --


? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?-- Start delete() --

現(xiàn)在介紹刪除功能:

下面的商品列表看起來是一個(gè)表格,實(shí)際上外層包含了一個(gè)表單標(biāo)簽,當(dāng)你點(diǎn)擊刪除時(shí),給刪除按鈕綁定了submit()事件,提交表單到對(duì)應(yīng)的action地址上去;

注意:要?jiǎng)h除某件商品時(shí),要在那件商品前打上勾,不然就直接跳到主頁而沒有變化了;

打上勾之后就有了:

$this->request->post['selected']; ? ? ? ? ?//這是所有勾選中的商品,值為商品id

<button type="button" data-toggle="tooltip" title="<?php echo $button_delete; ?>" class="btn btn-danger" onclick="confirm('<?php echo $text_confirm; ?>') ? $('#form-product').submit() : false;"><i class="fa fa-trash-o"></i></button> ? ? ? ? ?//刪除按鈕

<form action="<?php echo $delete; ?>" method="post" enctype="multipart/form-data" id="form-product"> ? ? ? ? ?//表單標(biāo)簽

$data['delete'] = $this->url->link('catalog/product/delete', 'token=' . $this->session->data['token'] . $url, 'SSL'); ? ? //調(diào)用controller中的delete方法

進(jìn)入delete方法:

首先加載相應(yīng)的資源:(大家都知道了);

若勾選中了該商品,并且該用戶有修改的權(quán)限:

if (isset($this->request->post['selected']) && $this->validateDelete()){}

進(jìn)入if后

到數(shù)據(jù)庫中循環(huán)刪除選中的商品:

foreach ($this->request->post['selected'] as $product_id) {

? $this->model_catalog_product->deleteProduct($product_id);

}

這里再次修改或確認(rèn)$url,其功能是:刪除某些數(shù)量商品后,還能夠保持在原有的頁數(shù)上,或是原來的篩選條件上;

$url = '';

if (isset($this->request->get['filter_name'])) {

? $url .= '&filter_name=' . urlencode(html_entity_decode($this->request->get['filter_name'], ENT_QUOTES, 'UTF-8'));

}

if (isset($this->request->get['filter_model'])) {

? $url .= '&filter_model=' . urlencode(html_entity_decode($this->request->get['filter_model'], ENT_QUOTES, 'UTF-8'));

}

if (isset($this->request->get['filter_price'])) {

? $url .= '&filter_price=' . $this->request->get['filter_price'];

}

if (isset($this->request->get['filter_quantity'])) {

? $url .= '&filter_quantity=' . $this->request->get['filter_quantity'];

}

if (isset($this->request->get['filter_status'])) {

? $url .= '&filter_status=' . $this->request->get['filter_status'];

}

if (isset($this->request->get['sort'])) {

? $url .= '&sort=' . $this->request->get['sort'];

}

if (isset($this->request->get['order'])) {

? $url .= '&order=' . $this->request->get['order'];

}

if (isset($this->request->get['page'])) {

? $url .= '&page=' . $this->request->get['page'];

}

if最后,刪除成功,跳轉(zhuǎn)到商品列表首頁:

$this->response->redirect($this->url->link('catalog/product', 'token=' . $this->session->data['token'] . $url, 'SSL'));

if外(也就是沒有選中任何商品):

$this->getList(); ? ? ? ? ?//就跟index方法一樣,只是單純的遍歷數(shù)據(jù)

? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?-- END delete() --


? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?-- Start add() --

下面是新增功能:

調(diào)用controller中的add方法:

$data['add'] = $this->url->link('catalog/product/add', 'token=' . $this->session->data['token'] . $url, 'SSL');

首先,加載相應(yīng)的資源;

一開始,$this->request->server['REQUEST_METHOD'] = GET,則不進(jìn)入if循環(huán),直接調(diào)用getForm()方法;

$this->getForm(); ? ? ? ? ?//加載要添加商品信息的表單

在getForm()方法中:

//首先重組url

//面包屑導(dǎo)航

//此時(shí)是加載表單的情況,因?yàn)橐晥D中<form action="<?php echo $action; ?>" method="post" enctype="multipart/form-data" id="form-product" class="form-horizontal">,所以這里要判斷是add還是edit

//因?yàn)閍dd和edit方法都調(diào)用了此方法,就根據(jù)是否傳遞了id來分別

if (!isset($this->request->get['product_id'])) {

? $data['action'] = $this->url->link('catalog/product/add', 'token=' . $this->session->data['token'] . $url, 'SSL');

} else {

? $data['action'] = $this->url->link('catalog/product/edit', 'token=' . $this->session->data['token'] . '&product_id=' . $this->request->get['product_id'] . $url, 'SSL');

}

//如果是編輯模式,則要先獲取原有的商品信息

//這里表示編輯模式

if (isset($this->request->get['product_id']) && ($this->request->server['REQUEST_METHOD'] != 'POST')) {

? $product_info = $this->model_catalog_product->getProduct($this->request->get['product_id']);

}

//再是根據(jù)有無$this->request->get['product_id']或有無$product_info,來設(shè)置表單中文本框等其中的值;(add模式則為空值,edit模式則顯示數(shù)據(jù)庫中的值)

//再加載公用模板

//加載表單文件

$this->response->setOutput($this->load->view('catalog/product_form.tpl', $data));

當(dāng)$this->request->server['REQUEST_METHOD'] =POST,也就是加載的表單提交之后:

//提交表單后,并驗(yàn)證通過

if (($this->request->server['REQUEST_METHOD'] == 'POST') && $this->validateForm())

//把提交的表單數(shù)據(jù)添加到數(shù)據(jù)庫

$this->model_catalog_product->addProduct($this->request->post);

//又是重整url

//提交表單,新增商品成功后,跳轉(zhuǎn)到商品列表首頁

$this->response->redirect($this->url->link('catalog/product', 'token=' . $this->session->data['token'] . $url, 'SSL'));

? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? -- END add() --

編輯和新增幾乎一模一樣,就不做介紹了。

其中的model文件都是sql操作,就沒有貼上來了;

本篇只是加深自己對(duì)此系統(tǒng)的認(rèn)知與記憶,希望大家多多指點(diǎn);

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。
  • 序言:七十年代末,一起剝皮案震驚了整個(gè)濱河市,隨后出現(xiàn)的幾起案子,更是在濱河造成了極大的恐慌,老刑警劉巖,帶你破解...
    沈念sama閱讀 228,333評(píng)論 6 531
  • 序言:濱河連續(xù)發(fā)生了三起死亡事件,死亡現(xiàn)場(chǎng)離奇詭異,居然都是意外死亡,警方通過查閱死者的電腦和手機(jī),發(fā)現(xiàn)死者居然都...
    沈念sama閱讀 98,491評(píng)論 3 416
  • 文/潘曉璐 我一進(jìn)店門,熙熙樓的掌柜王于貴愁眉苦臉地迎上來,“玉大人,你說我怎么就攤上這事。” “怎么了?”我有些...
    開封第一講書人閱讀 176,263評(píng)論 0 374
  • 文/不壞的土叔 我叫張陵,是天一觀的道長(zhǎng)。 經(jīng)常有香客問我,道長(zhǎng),這世上最難降的妖魔是什么? 我笑而不...
    開封第一講書人閱讀 62,946評(píng)論 1 309
  • 正文 為了忘掉前任,我火速辦了婚禮,結(jié)果婚禮上,老公的妹妹穿的比我還像新娘。我一直安慰自己,他們只是感情好,可當(dāng)我...
    茶點(diǎn)故事閱讀 71,708評(píng)論 6 410
  • 文/花漫 我一把揭開白布。 她就那樣靜靜地躺著,像睡著了一般。 火紅的嫁衣襯著肌膚如雪。 梳的紋絲不亂的頭發(fā)上,一...
    開封第一講書人閱讀 55,186評(píng)論 1 324
  • 那天,我揣著相機(jī)與錄音,去河邊找鬼。 笑死,一個(gè)胖子當(dāng)著我的面吹牛,可吹牛的內(nèi)容都是我干的。 我是一名探鬼主播,決...
    沈念sama閱讀 43,255評(píng)論 3 441
  • 文/蒼蘭香墨 我猛地睜開眼,長(zhǎng)吁一口氣:“原來是場(chǎng)噩夢(mèng)啊……” “哼!你這毒婦竟也來了?” 一聲冷哼從身側(cè)響起,我...
    開封第一講書人閱讀 42,409評(píng)論 0 288
  • 序言:老撾萬榮一對(duì)情侶失蹤,失蹤者是張志新(化名)和其女友劉穎,沒想到半個(gè)月后,有當(dāng)?shù)厝嗽跇淞掷锇l(fā)現(xiàn)了一具尸體,經(jīng)...
    沈念sama閱讀 48,939評(píng)論 1 335
  • 正文 獨(dú)居荒郊野嶺守林人離奇死亡,尸身上長(zhǎng)有42處帶血的膿包…… 初始之章·張勛 以下內(nèi)容為張勛視角 年9月15日...
    茶點(diǎn)故事閱讀 40,774評(píng)論 3 354
  • 正文 我和宋清朗相戀三年,在試婚紗的時(shí)候發(fā)現(xiàn)自己被綠了。 大學(xué)時(shí)的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片。...
    茶點(diǎn)故事閱讀 42,976評(píng)論 1 369
  • 序言:一個(gè)原本活蹦亂跳的男人離奇死亡,死狀恐怖,靈堂內(nèi)的尸體忽然破棺而出,到底是詐尸還是另有隱情,我是刑警寧澤,帶...
    沈念sama閱讀 38,518評(píng)論 5 359
  • 正文 年R本政府宣布,位于F島的核電站,受9級(jí)特大地震影響,放射性物質(zhì)發(fā)生泄漏。R本人自食惡果不足惜,卻給世界環(huán)境...
    茶點(diǎn)故事閱讀 44,209評(píng)論 3 347
  • 文/蒙蒙 一、第九天 我趴在偏房一處隱蔽的房頂上張望。 院中可真熱鬧,春花似錦、人聲如沸。這莊子的主人今日做“春日...
    開封第一講書人閱讀 34,641評(píng)論 0 26
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽。三九已至,卻和暖如春,著一層夾襖步出監(jiān)牢的瞬間,已是汗流浹背。 一陣腳步聲響...
    開封第一講書人閱讀 35,872評(píng)論 1 286
  • 我被黑心中介騙來泰國打工, 沒想到剛下飛機(jī)就差點(diǎn)兒被人妖公主榨干…… 1. 我叫王不留,地道東北人。 一個(gè)月前我還...
    沈念sama閱讀 51,650評(píng)論 3 391
  • 正文 我出身青樓,卻偏偏與公主長(zhǎng)得像,于是被迫代替她去往敵國和親。 傳聞我的和親對(duì)象是個(gè)殘疾皇子,可洞房花燭夜當(dāng)晚...
    茶點(diǎn)故事閱讀 47,958評(píng)論 2 373

推薦閱讀更多精彩內(nèi)容