开发者

Why am I getting errors when I put my views inside sub-folder in CI 2.0+?

I am making a simple application and I am familiar with CodeIgniter 1.7.3, which I didn't have any problems putting sub folders into the application/views folder.

My problem is specifically when I try and load the view, I get the standard CI error message of An Error Was Encountered Unable to load the requested file: usercontentpages/testview.php

However if I move the view file out of the s开发者_StackOverflow社区ub folder and place it in the application/views folder the load view command works fine?

I can't find any documentation in the user guide on why this is so?

Here is my Controller:

    <?php
class Pages extends CI_Controller
{

//Controller Constructor
    public function __construct()
    {
        parent::__construct();
    }

    //Home Page (Default)
    public function index()
    {       
         //Loading a Partial View
         $mContent = $this->load->view('home', '', TRUE); //this works
        //$mContent = $this->load->view('subfolder/home', '', TRUE); //this doesn't work

         $data = array(
             'mainContent' => $mContent,
         );
         //Passing the partial view to the master page
         $this->load->view('usermasterpage', $data);
    }
}
?>

Here is my Master Page:

<?php
//Doctype
echo doctype('html');
?>
<html>
<head>
    <meta charset="utf-8">

</head>
<body onload="OnLoad()">
    <div id="wrap">

        <!-- Main Content Div -->
        <div id="mainContent">
        <?php 
            /* Every page will have a main content area */
            if(isset($mainContent))
            {
                echo $mainContent;
            }
        ?>
        </div>
    </div>
</body>

And Finally here is the page snippet I'm trying to load:

<p>Hi there</p>


CodeIgniter will successfully use nested views: I use nested views all the time and I know others who do as well, and it works out of the box. Show some code so we can see what you're doing wrong.


The CodeIgniter documentation says precisely that you can.

Your view files can also be stored within sub-folders if you prefer that type of organization. When doing so you will need to include the folder name loading the view. Example:

$this->load->view('folder_name/file_name');

http://codeigniter.com/user_guide/general/views.html

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜