Internship Summary Eight: Create a new page--Add a route file

Source: Internet
Author: User
When you create a new page, you add a route to the page in the appropriate global.php file and add the appropriate action to the controller.

Route 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:

 Publicfunction 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=NewViewModel (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=NewViewModel (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 that needs to be created, in which the layout is written.

This is the exact steps to create a new page.

Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

The above introduces the internship summary eight: Create a new Web page-add routing files, including the content of the area, I hope to be interested in PHP tutorial friends helpful.

  • Related Article

    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.