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

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

报告相同问题?

悬赏问题

  • ¥15 metadata提取的PDF元数据,如何转换为一个Excel
  • ¥15 关于arduino编程toCharArray()函数的使用
  • ¥100 vc++混合CEF采用CLR方式编译报错
  • ¥15 coze 的插件输入飞书多维表格 app_token 后一直显示错误,如何解决?
  • ¥15 vite+vue3+plyr播放本地public文件夹下视频无法加载
  • ¥15 c#逐行读取txt文本,但是每一行里面数据之间空格数量不同
  • ¥50 如何openEuler 22.03上安装配置drbd
  • ¥20 ING91680C BLE5.3 芯片怎么实现串口收发数据
  • ¥15 无线连接树莓派,无法执行update,如何解决?(相关搜索:软件下载)
  • ¥15 Windows11, backspace, enter, space键失灵