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.