OpenCart是一套老牌的開源自由B2C電商系統(tǒng),最近watch了其托管在在github上的項(xiàng)目,發(fā)現(xiàn)還是很活躍的,每天都有人反饋bug。
初步的看一下,它是支持在后臺管理多個店鋪的,而且可以同一個商品在不同店鋪有不同的價格;店鋪之間可以綁定不同的域名。這是一個比較有特色的地方。
但查看它的代碼,就發(fā)現(xiàn)多年來改動很小,在代碼的分工上,沒有進(jìn)化的感覺。
大量本該由視圖來進(jìn)行構(gòu)造的數(shù)據(jù)如語言、鏈接、當(dāng)前路徑等,都放到控制器中,
像前臺登錄頁面:
$data['breadcrumbs'] = array(); $data['breadcrumbs'][] = array( 'text' => $this->language->get('text_home'), 'href' => $this->url->link('common/home') ); $data['breadcrumbs'][] = array( 'text' => $this->language->get('text_account'), 'href' => $this->url->link('account/account', '', 'SSL') ); $data['breadcrumbs'][] = array( 'text' => $this->language->get('text_login'), 'href' => $this->url->link('account/login', '', 'SSL') ); $data['heading_title'] = $this->language->get('heading_title'); $data['text_new_customer'] = $this->language->get('text_new_customer'); $data['text_register'] = $this->language->get('text_register'); $data['text_register_account'] = $this->language->get('text_register_account'); $data['text_returning_customer'] = $this->language->get('text_returning_customer'); $data['text_i_am_returning_customer'] = $this->language->get('text_i_am_returning_customer'); $data['text_forgotten'] = $this->language->get('text_forgotten'); $data['entry_email'] = $this->language->get('entry_email'); $data['entry_passWord'] = $this->language->get('entry_password'); $data['button_continue'] = $this->language->get('button_continue'); $data['button_login'] = $this->language->get('button_login'); if (isset($this->error['warning'])) { $data['error_warning'] = $this->error['warning']; } else { $data['error_warning'] = ''; } $data['action'] = $this->url->link('account/login', '', 'SSL'); $data['register'] = $this->url->link('account/register', '', 'SSL'); $data['forgotten'] = $this->url->link('account/forgotten', '', 'SSL');相當(dāng)累贅,其實(shí)在現(xiàn)有框架特性下,完全可以放到視圖文件中去的。
在視圖文件的頭部:
<?php$lang = $this->registry->get('language');//加載語言包管理對象$url = $this->registry->get('url');//加載url對象$this->language('common/footer');//載入語言包?><footer> <div class="container"> <div class="row"> <?php if ($informations) { ?> <div class="col-sm-3"> <h5><?php echo $lang->get('text_information'); ?></h5> <ul class="list-unstyled"> <?php foreach ($informations as $information) { ?> <li><a href="<?php echo $information['href']; ?>"><?php echo $information['title']; ?></a></li> <?php } ?> </ul> </div> <?php } ?>這樣控制器中就不用再管這種無聊的事情,而集中精力負(fù)責(zé)業(yè)務(wù)邏輯和核心數(shù)據(jù)的調(diào)用了。
新聞熱點(diǎn)
疑難解答
圖片精選