: This article mainly introduces practice Summary 8: create a new webpage-add a route file. For more information about PHP tutorials, see. When creating a new webpage, you must add the webpage route in the corresponding global. php file and add the corresponding action to the controller.
Routing code:
'cat-types' => array( 'type' => 'segment', 'options' => array( 'route' => '/cat/:type_name/', 'constraints' => array( 'type_name' => '[a-zA-Z0-9_-]+' ), 'defaults' => array( 'controller' => 'Top10Inaction\Controller\index', 'action' => 'catProducts' ) ) ),
CatProductsAction code:
public function catProductsAction() { $type_name=$this->params()->fromRoute('type_name', null); $sort=$this->getRequest()->getQuery('sort', null); $industry=$this->getTypeCollection()->getIndustryByName($type_name); $subject=$this->getSubjectCollection()->getSubjectsByIndustry($industry); $type=$this->getTypeCollection()->getTypeByName($type_name); $display_name=$type->display_name; $default_sort=array('price','overall_score'); if($this->isMobile()) { $this->layout('layout/mobile'); $view=new ViewModel(array( )); $view->setTemplate('mobile/cat-products'); return$view; } else { $product_groups=array(); if(!(in_array($sort, $default_sort))) { $sort='overall_score'; } $sortby=array($sort=>-1); $condition=array('type_name'=>$type_name); $products=$this->getProductCollection()->getPaginator('product', array( 'condition'=>$condition, 'sortby'=>$sortby, )); $products->setItemCountPerPage(0); $totalItemCount=$products->getPages()->totalItemCount; $view=new ViewModel(array( 'type_name'=>$type_name, 'products'=>$products, 'industry'=>$industry, 'subject'=>$subject, 'totalItemCount'=>$totalItemCount, 'display_name'=>$display_name, )); $view->setTemplate('index/cat-products'); return$view; } }
The content in the above $ view-> setTemplate is the cat-products.phtml file to be created, writing layout in it and so on.
The preceding steps are used to create a new webpage.
Copyright Disclaimer: This article is an original article by the blogger and cannot be reproduced without the permission of the blogger.
The above introduces practice Summary 8: create a new webpage-add a route file, including some content, and hope to be helpful to friends who are interested in PHP tutorials.