The code is more than three thousand, but the most important feature in prestashop 1.4 is frontcontroller. php.
Analysis
Let's take a look at the file Loading Method of prestashop 1.4. If you have a new class, the code will first look for class files with the same name in the controller, which is similar to the previous version. If it cannot be found, you can search for the override folder where the user can customize the class. If it still cannot be found, you will use exec to create a class file with the request name, then load the class name + core class under classes. Therefore, you need to find the real frontcontroller. php under classes, and the class name is also frontcontrollercore.
If the most important thing is init. PHP, frontcontroller in prestashop 1.4. PHP takes over all the work of init and replaces the previous header. PHP, index. PHP and footer. all PHP work, including paging and commodity sorting. In short, frontcontroller. PHP is a bit like the dispatch of Zend framework. It is a signal to start all work.
public function run(){$this->init();$this->preProcess();$this->setMedia();$this->displayHeader();$this->process();$this->displayContent();$this->displayFooter();}if ($this->ssl AND !(isset($_SERVER[‘HTTPS‘]) AND strtolower($_SERVER[‘HTTPS‘]) == ‘on‘) AND Configuration::get(‘PS_SSL_ENABLED‘)){header(‘HTTP/1.1 301 Moved Permanently‘);header(‘Location: ‘.Tools::getShopDomainSsl(true).$_SERVER[‘REQUEST_URI‘]);exit();}
Auto 301 in function init, which is the new feature of prestashop 1.4. The maindomin Module I wrote is useless.
$page_name = (preg_match(‘/^[0-9]/‘, $page_name)) ? ‘page_‘.$page_name : $page_name;
The $ page_name variable in function init makes it easy to make judgments for different templates on different pages. You need to know that in the previous versions, I still directly make a judgment in header. TPL.
Tools::addCSS(_THEME_CSS_DIR_.‘global.css‘, ‘all‘);Tools::addJS(array(_PS_JS_DIR_.‘tools.js‘, _PS_JS_DIR_.‘jquery/jquery-1.4.4.min.js‘, _PS_JS_DIR_.‘jquery/jquery.easing.1.3.js‘));
In function setmedia, the advantage is that the CSS and JS can be managed in a unified manner, and the "CCC" of prestashop can be implemented. Combine, compress and Cache
Function productsort and pagination take over the previous work of sort and pagination.
Others have not changed much. The main function is to copy the past init. php. Even the names of variables are still global variables, rather than the global class in the object-oriented model.
Customization
In the override/classes folder, you can find a _ frontcontroller. PHP, which is actually a custom frontcontroller. in the PHP example, delete "_" and access the page to view the debug information. Note that there are two files, MySQL and module, in the same folder. If only frontcontroller. php is modified, the system will fail to run due to an error. Line 3 of _ frontcontroller. php is required
error_reporting(E_ALL | E_STRICT);
Change
error_reporting(7);
If you do not understand the meaning of this 7, you can refer to the Manual to learn.
To customize frontcontroller. php, or create a new file named frontcontroller. php In the override/classes folder, and write a class extends frontcontrollercore. The method can overwrite the method in the core.
Example:
class FrontController extends FrontControllerCore{function setMedia(){parent::setMedia();Tools::addCSS(_THEME_CSS_DIR_.‘addition.css‘);} public function displayFooter(){global $cookie, $smarty;if (!self::$initialized)$this->init(); self::$smarty->assign(array(‘HOOK_RIGHT_COLUMN‘ => (($smarty->get_template_vars(‘page_name‘) == ‘category‘) ? ‘‘ : Module::hookExec(‘rightColumn‘, array(‘cart‘ => self::$cart))),‘HOOK_FOOTER‘ => Module::hookExec(‘footer‘),‘content_only‘ => (int)(Tools::getValue(‘content_only‘))));self::$smarty->display(_PS_THEME_DIR_.‘footer.tpl‘);//live editif ($cookie->live_edit AND $ad = Tools::getValue(‘ad‘)){self::$smarty->assign(array(‘ad‘ => $ad, ‘live_edit‘ => true));self::$smarty->display(_PS_ALL_THEMES_DIR_.‘live_edit.tpl‘);}elseTools::displayError();}}
In this example, the setmedia and displayfooter methods are rewritten.
When rewriting setmedia, the method of the original frontcontroller is executed, and a new CSS is loaded in CSS.
When displayfooter is rewritten, the original code is copied. The only change is to add a judgment. If pagename is category, the column on the right is not output. This is to make the category list more space.
Prestashop 1.4 code analysis: the region of weak water three thousand