简体   繁体   English

如何在cakephp中创建类别页面链接?

[英]How can i create category page link in cakephp?

How can i create category page link in cakephp? 如何在cakephp中创建类别页面链接?

<?php if(count($cat)>0): foreach($cat as $cat_item): ?>  
<li>  
<a href="<?php Router::url('/', true); ?>category/<?php echo $cat_item['CatModel']['caturl']; ?>">  
    <?php echo $cat_item['CatModel']["catname"];  ?></a>  
</li>  
<?php endforeach; else: ?>  
<p class="no-record"></p>  
<?php endif; ?>  

You need to do 4 steps : 您需要执行4个步骤:

  • Create link in view (as you did) 在视图中创建链接(与您一样)
  • Create Route for that link 为该链接创建路线
  • Create Function in relevant controller 在相关控制器中创建功能
  • Create view for that function. 创建该功能的视图。

If you wish to use the HTML helper you can use this. 如果您希望使用HTML帮助器,则可以使用它。

<li>
    <?= $this->Html->link(__($cat_item['CatModel']['catname']), ['controller' => 'Categories', 'action' => 'view', $cat_item['CatModel']['id']]); ?>  
</li>

Assuming your category controller is called "CategoriesController.php", and is located in src/Controller 假设您的类别控制器称为“ CategoriesController.php”,并且位于src / Controller中

In general, you can use the cake client from the command line to generate models/controllers/views if you follow the cake schema naming convention. 通常,如果您遵循Cake模式命名约定,则可以从命令行使用Cake客户端生成模型/控制器/视图。

bin/cake bake template categories 垃圾桶/蛋糕烘烤模板类别

If you wish to see the cake way of doing things. 如果您希望看到做事的蛋糕方式。 It will generate your view. 它将生成您的视图。 Also for more information on the HTML helper check out the CookBook . 有关HTML帮助程序的更多信息,请查看CookBook

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何设置类别链接以显示自定义页面模板? - How can I set a category link to show a custom page template? cakephp:如何在cakephp中编写此链接 - cakephp : How can i write this link in cakephp CakePHP:如何使用“漂亮”网址选择一个类别的所有元素? (/类别/ NAME_OF_CATEGORY) - CakePHP: How can I select all elements of one category with a “nice” url? (/category/NAME_OF_CATEGORY) cakephp:如何显示每个类别的计数? - cakephp : how can i display count for each category? 如何在Joomla上检测类别页面? - How can i detect category page on Joomla? 如何在cakephp中更改索引页面? - How I can change index page in cakephp? 如何使用MySQL和PHP从与父类别关联的页面创建指向子类别的链接 - How to create a link to a sub category from a page that is associated with a parent category using MySQL & PHP Wordpress:如何创建包含1个特定类别的帖子的外部页面或文件? - Wordpress: How can I create an external page or file that contains posts with 1 specific category? 如何创建特殊链接,以便单击该链接的用户可以访问某个注册页面? - How do I create a special link so that the user who clicked on that link can access a certain registration page? 我如何获得没有链接的帖子的类别名称? - How can I get the category name of a post without a link?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM