Search code examples
phpcodeignitercodeigniter-2

codeigniter issue with loading view from controller


I am new to codeigniter and really interested in trying it out. I followed the guide but ran into a problem. It seems like I am unable to load my first page properly.

I have inside the view folder another folder called general and inside it index.php.

in controller folder, I have sub-folder with general and inside it is Default controller.

I have the following route and yet the page showing is blank

$route['default_controller'] = "general/default";
$route['404_override'] = '';

When I visit the link, I type this in browser:

http://localhost:8888/treventa/

and the screen is blank. Am I doing something wrong? Sorry if this is too simple but a person got to learn from his mistake :)


Solution

  • Try with me step by step:

    • Firstly: the Controller:

    (main.php) File content

    if (!defined('BASEPATH'))exit('No direct script access allowed');
    
    class Main extends CI_Controller {
    
        public function index() {
            $this->load->view('general/welcome');
        }
    }
    
    • Secondly: The view:

    (welcome.php) File content
    You can put anything you want

    <h1> Hello, I'm the view file  </h1>
    
    • Finaly: The routes:

    (routes.php) File content

    $route['default_controller'] = "general/main";
    

    Now call the script like this http://localhost/codeIgniter/, that's where codeIgniter is the script folder name.

    I think everything now is clear.