OpenCart is an established open source free-to-business e-commerce system that recently watch its hosting in
GitHubOn the project, the discovery is still very active, every day people feedback the bug.
First of all, it is to support the management of multiple stores in the background, and can be the same product in different stores have different prices; stores can be tied to different domain names. This is a more distinctive place.
But by looking at its code, we found that the changes were small over the years, and there was no evolutionary sense in the division of Code.
A large number of data, such as languages, links, current paths, etc., that should be constructed by the view, are placed in the controller,
Like the front desk login page:
$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 ');
Quite cumbersome, in fact, under the existing framework features, can be put into the view file.
On the head of the view file:
$lang = $this->registry->get('language');//加载语言包管理对象$url = $this->registry->get('url');//加载url对象$this->language('common/footer');//载入语言包?>
Class="Container"> class="Row"> <?Phpif($informations){?>Class="Col-sm-3"><? PHP echo$lang->get(' text_information '); ?>
class= "list-unstyled"> < ? PHP foreach($informationsas$information) { ?>
- " $information[' href '];?>"><? PHP echo$information[' title ']; ?>
< ? PHP} ?>
<?PHP}?>
In this way the controller does not have to take care of this boring thing, and focus on the business logic and core data calls.
Here's a little advice on opencart, including GitHub, and hopefully help a friend who is interested in PHP tutorials.