班级
public function load($page = 'resources')
{
if ( ! file_exists(APPPATH.'views/resources/'.$page.'.php'))
{
// Whoops, we don't have a page for that!
show_404();
}
$data['title'] = ucfirst($page); // Capitalize the first letter
$this->load->view('templates/header', $data);
$this->load->view('resources/multiplication'.$page, $data);
$this->load->view('templates/footer', $data);
}
目录
-Application
--views
---resources
----multiplication
-----selector.php
我正在尝试使用localhost:// resources / load / selector加载selector.php,但它只显示404。我无法使这些类与视图文件夹中的子目录一起使用。
如果我将选择器移至/ resources,则不会加载任何问题。 如何获得加载方法来加载selector.php?
答案 0 :(得分:0)
这是因为在加载视图之前,您必须先加载404错误。您应该删除该条件或将其编辑为您的真实路径:
public function load($page = 'resources')
{
if ( ! file_exists(APPPATH.'views/resources/multiplication/'.$page.'.php')) //Just added the multiplication to make it the right path
{
// Whoops, we don't have a page for that!
show_404();
}
$data['title'] = ucfirst($page); // Capitalize the first letter
$this->load->view('templates/header', $data);
$this->load->view('resources/multiplication'.$page, $data);
$this->load->view('templates/footer', $data);
}
答案 1 :(得分:0)
在两种情况下,您只是在AmazonAPIGatewayAdministrator
之前缺少/
:
$page
正如爱德华多(Eduardo)所暗示的,仅供参考,public function load($page = 'resources')
{
if ( ! file_exists(APPPATH.'views/resources/multiplication/'.$page.'.php')) //Just added the multiplication to make it the right path
{
// Whoops, we don't have a page for that!
show_404();
}
$data['title'] = ucfirst($page); // Capitalize the first letter
$this->load->view('templates/header', $data);
$this->load->view('resources/multiplication/'.$page, $data);
$this->load->view('templates/footer', $data);
}
并不是必需的,而且实际上更加令人困惑。在CI中,如果视图不存在,它将告诉您该视图不存在。但是,如果您想避免这样的消息,那么您在做什么就可以了。