首页 / PHP / 实习小结八:创建新网页--添加路由文件
实习小结八:创建新网页--添加路由文件
内容导读
互联网集市收集整理的这篇技术教程文章主要介绍了实习小结八:创建新网页--添加路由文件,小编现在分享给大家,供广大互联网技能从业者学习和参考。文章包含1843字,纯文字阅读大概需要3分钟。
内容图文
![实习小结八:创建新网页--添加路由文件](/upload/InfoBanner/zyjiaocheng/155/872b685b765e496888dd7abdd0ed3a15.jpg)
路由代码:
'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教程有兴趣的朋友有所帮助。
内容总结
以上是互联网集市为您收集整理的实习小结八:创建新网页--添加路由文件全部内容,希望文章能够帮你解决实习小结八:创建新网页--添加路由文件所遇到的程序开发问题。 如果觉得互联网集市技术教程内容还不错,欢迎将互联网集市网站推荐给程序员好友。
内容备注
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 gblab@vip.qq.com 举报,一经查实,本站将立刻删除。
内容手机端
扫描二维码推送至手机访问。