我是 CodeIgniter 的新手。我正在使用 Bootstrap 模板。 welcome_page.php 是我的 View 文件。我试图链接我的主页按钮以重定向到另一个页面“dashboard.php”,该页面位于我的元素的 View 文件夹中。我收到错误消息“_访问被禁止_或_对象未找到_”。
谁能告诉我如何用示例链接页面。感谢您的帮助。
Controller 文件代码:
public function home()
{
$this->load->view('dashboard');
}
查看文件代码:
<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>
最佳答案
任何 MVC 框架的入口点都是 Controller ,您不能直接访问 View 。
在 CodeIgniter 中,url 由 Controller 名称和操作名称( Controller 中的公共(public)方法)组成。
例如,如果您想要网址
localhost/index.php/welcome/dashboard
.您需要有一个名为 Welcome
的 Controller 类以及该 Controller 中名为 dashboard
的公共(public)方法.您可以通过输入命令 $this->load->view('welcome_message');
来显示 View 在函数中 dashboard
.
网址格式:
<Your project root>/index.php/<small caps of the controller name>/<name of the public function in the controller>
所有这些意味着您只需要添加函数 dashboard
到名为 Welcome
的 Controller .
您的 Controller 应如下所示。
public function home()
{
$this->load->view('dashboard');
}
public function dashboard()
{
$this->load->view('welcome_page');
}
现在你可以访问 url localhost/index.php/welcome/dashboard
您可以在他们的教程中阅读更多内容 https://codeigniter.com/user_guide/tutorial/static_pages.html#static-pages
关于PHP - 如何在 ci 中链接 View 中的其他页面,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53767952/