在创建一个新网页时,要在相应的global.php文件中添加该网页的路由,并且在controller中添加相应的action。
路由代码:
'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代码:
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; } }
上面的$view->settemplate中的内容就是需要创建的cat-products.phtml文件,在其中写入布局之类的。
以上就是创建新网页的具体步骤。
版权声明:本文为博主原创文章,未经博主允许不得转载。
以上就介绍了实习小结八:创建新网页--添加路由文件,包括了方面的内容,希望对php教程有兴趣的朋友有所帮助。