简体   繁体   English

如何在CodeIgniter中为子目录创建适当的索引页

[英]How to make a proper index page for subdirectories in CodeIgniter

I'm building an app that has a section for consumers and businesses, and I want to separate the controllers folder appropriately, so it looks like this - 我正在构建一个针对消费者和企业的版块的应用,并且我想适当地分隔controllers文件夹,所以它看起来像这样-

http://domain.com/users/signup/
http://domain.com/business/signup/

I have it working by creating a separate folder for each section in the "controllers" folder, but I want to know how to make an appropriate page when the user visits the http://domain.com/users/ . 我通过为“ controllers”文件夹中的每个部分创建一个单独的文件夹来使其工作,但是我想知道当用户访问http://domain.com/users/时如何制作适当的页面。 It currently just loads the homepage. 当前它仅加载主页。 How can I fix this? 我怎样才能解决这个问题?

You don't need to put them in separate folders for this to work. 您无需将它们放在单独的文件夹中即可工作。

File system/application/controllers/users.php: 文件系统/应用程序/控制器/users.php:

<?php
class Users extends Controller {
    function index() {
        // this function will be called at http://domain.com/users
    }

    function signup() {
        // this function will be called at http://domain.com/users/signup
    }
}
?>

File system/application/controllers/business.php: 文件系统/应用程序/控制器/business.php:

<?php
class Business extends Controller {
    function index() {
        // this function will be called at http://domain.com/business
    }

    function signup() {
        // this function will be called at http://domain.com/business/signup
    }
}
?>

If I understand your question correct, you might be looking for URI Routing . 如果我对您的问题的理解正确,那么您可能正在寻找URI路由 I don't see why you would need folders for this. 我不明白为什么您需要为此使用文件夹。 Simply just create the routes you need and make use of the index methods in the controllers for making the "homepage" for both users and business. 只需创建所需的路由并利用控制器中的索引方法为用户和企业创建“主页”即可。

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

相关问题 如何将没有索引文件的子目录重定向到 404 页面 - how to redirect subdirectories having no index file to 404 page Codeigniter:索引页面创建 - Codeigniter: Index page creation 如何在Codeigniter中激活动态页面 - how to make a page active for dynamic in codeigniter PHP如何获取所有子目录中的所有文件(仅html文件)并为每个html页面建立索引 - PHP how to get all files(only html files) in all subdirectories and index each html page EC2 上的 CodeIgniter 将索引显示为空白页。 怎么修? - CodeIgniter on EC2 showing index as blank page. How to fix? Codeigniter视图:如何为视图创建子目录? - Codeigniter views: How can I create subdirectories for my views? 从数据库中分解数组的正确方法如何使其成为 Codeigniter 下拉列表中的选项 - How the proper way to explode array from database make it as option in dropdown in Codeigniter 如何通过.htaccess创建动态目录和子目录 - How to make dynamic directories and subdirectories via .htaccess 如何使用CodeIgniter下的钩子禁止访问页面 - How to make a page access Forbidden with a hook under CodeIgniter 在Codeigniter中,如何使控制器运行index()而不用在url中写入/ index? - In Codeigniter, how to make controller run index() without having to write /index in url?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM