Spaceliving
Spaceliving

Reputation: 81

cannot create sub directories in Views for Code Igniter frame work

i have a website i am running under CodeIgniter www.nationalpaymentcard.com

For awhile now i have ad the website running fine but have all my pages set up in the Views folder. I was trying to make a sub directory in there like Views/NewsPosts/post1.php to organize my files a little better but if i ever do that i get a 404.

Now i have been researching for awhile but i guess im not sure what exactly to google to figure out what i need to do. I was hoping someone out there on the internets could help point me the right way. Im thinking i may need to configure my controllers.php file but im not sure how... or if i need to add another one.

this is my current controllers.php

class Pages extends CI_Controller {

    public function view($page = 'home')
    {   
        if ( ! file_exists('application/views/pages/'.$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('pages/'.$page, $data);
        $this->load->view('templates/footer', $data);
    }
}

any help is greatly appreciated! Thank you!

Upvotes: 0

Views: 66

Answers (1)

Minhaz
Minhaz

Reputation: 446

Its look like your 'if' condition is not right, if you change the if it should work

if ( ! file_exists(VIEWPATH.'pages/'.$page.'.php'))
{
    // Whoops, we don't have a page for that!
    show_404();
}

Upvotes: 2

Related Questions