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() 
     {
         $this->load->view('dashboard');
     }

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>
 </a>
 </li>
  • 写回答

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() 
         {
             $this->load->view('dashboard');
         }
    
    public function dashboard() 
         {
             $this->load->view('welcome_page');
         }
    

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

    You can read more in their tutorial https://codeigniter.com/user_guide/tutorial/static_pages.html#static-pages

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

报告相同问题?

悬赏问题

  • ¥100 Jenkins自动化部署—悬赏100元
  • ¥15 关于#python#的问题:求帮写python代码
  • ¥20 MATLAB画图图形出现上下震荡的线条
  • ¥15 关于#windows#的问题:怎么用WIN 11系统的电脑 克隆WIN NT3.51-4.0系统的硬盘
  • ¥15 perl MISA分析p3_in脚本出错
  • ¥15 k8s部署jupyterlab,jupyterlab保存不了文件
  • ¥15 ubuntu虚拟机打包apk错误
  • ¥199 rust编程架构设计的方案 有偿
  • ¥15 回答4f系统的像差计算
  • ¥15 java如何提取出pdf里的文字?