关于OpenCart的一个小建议
程序员文章站
2023-12-23 16:05:22
...
OpenCart是一套老牌的开源*B2C电商系统,最近watch了其托管在在github上的项目,发现还是很活跃的,每天都有人反馈bug。
初步的看一下,它是支持在后台管理多个店铺的,而且可以同一个商品在不同店铺有不同的价格;店铺之间可以绑定不同的域名。这是一个比较有特色的地方。
但查看它的代码,就发现多年来改动很小,在代码的分工上,没有进化的感觉。
大量本该由视图来进行构造的数据如语言、链接、当前路径等,都放到控制器中,
像前台登录页面:
$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');
相当累赘,其实在现有框架特性下,完全可以放到视图文件中去的。
在视图文件的头部:
$lang = $this->registry->get('language');//加载语言包管理对象$url = $this->registry->get('url');//加载url对象$this->language('common/footer');//载入语言包?>