Practice summary 8: create a new webpage-add a route file

Source: Internet
Author: User
: 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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.