dongping9475 2018-12-13 18:20
浏览 76

PHP - 如何在ci中链接视图中的其他页面

I am new to CodeIgniter. I am using a bootstrap template. welcome_page.php is my view file. I have tried to link my home button to redirect to another page that is 'dashboard.php' which is in view folder of my project. I am getting an error "_the access is forbidden_ or _object is not found_".
Can anyone tell me how to link pages with an example. Thanks for the help.

controller file code:

 public function home() 

view file code:

<li class="nav-item active">
 <a class="nav-link" href="<?php echo BASE_PATH . "views/dashboard.php";?>">Home
    <span class="sr-only">(current)</span>
  • 写回答

1条回答 默认 最新

  • douchuoliu4422 2018-12-13 18:59

    The entry point for any MVC framework is the controller and you cannot access views directly.

    In CodeIgniter, the url is composed of controller name and action name (public method in controller). For example if you want the url localhost/index.php/welcome/dashboard. You need to have a controller class called Welcome and a public method in that controller called dashboard. You can display the view by putting the command $this->load->view('welcome_message'); in function dashboard. Url format:

    <Your project root>/index.php/<small caps of the controller name>/<name of the public function in the controller>

    All of this means that you just need to add function dashboard to your controller named Welcome. Your controller should look like this.

    public function home() 
    public function dashboard() 

    Now you can access url localhost/index.php/welcome/dashboard

    You can read more in their tutorial

    本回答被题主选为最佳回答 , 对您是否有帮助呢?



  • ¥15 求全国交通咨询模拟代码,要求如下,可以完全在dev c++运行
  • ¥15 根据要求修改程序编码
  • ¥15 用 Python 做一个用 Excel 表导入的答题系统
  • ¥15 使用微信开发者工具实现一个“婚博会”小程序
  • ¥15 ros的rviz仿真机器人
  • ¥15 关于#linux#的问题(输入输出错误):出现这个界面接着我重新装系统,又让修电脑的师傅帮我扫描硬盘(没有问题)用着用着又卡死(相关搜索:固态硬盘)
  • ¥15 cv::resize不同线程时间不同
  • ¥15 web课程,怎么做啊😭没好好听课 根本不知道怎么下手
  • ¥15 做一个关于单片机的比较难的代码,然后搞一个PPT进行解释
  • ¥15 python提取.csv文件中的链接会经常出现爬取失败