Codeigniter Issue With Loading View Page

Hi All

Please help me before i pull my hair out and burn it. :weary: :joy:

I’m learning codeigniter and trying to create an ajax form that submits to the database. I’m new to OOP & MVC and starting to get my head round it except in trying to create the form i’m getting an error of “Unable to load the requested file: contact/index” but have no idea why as the ->view points straight to it. I have header and footer working ok if i take the main page view out of the equation. Please can one of you kind folk look over my controller & model to see if there is something i’m missing? I feel there is something super obvious i’m missing but i’ve been staring at it too long to see.

The index file is located as follows: views/contact/index/php.
Also i have set a route to the file as follows:-

$route['contact'] = 'contact/index';



defined('BASEPATH') OR exit('No direct script access allowed');

class Contact extends CI_Controller 
    // construct
    public function __construct() 
        $this->load->model('Contactmodel', 'contactmodel');     
    // index contactmodel 
    public function index() 
        $data = array();
        $data['metaDescription'] = 'Contact Form Meta Desc';
        $data['metaKeywords'] = 'Contact Form Keywords';
        $data['title'] = "Contact Us";
        $this->load->view('contact/index', $data);
    // submit contact form
    public function submitEnquiry()
        $json = array();
            $name = $this->input->post('name');
            $email     = $this->input->post('email');           
            $contactNo = $this->input->post('contact_no');
            $note  = $this->input->post('note');
            $enquiry  = $this->input->post('enquiry');
            // name validation
                $json['error']['name'] = 'Please enter full name';
            // email validation
                $json['error']['email'] = 'Please enter email address';
            // check email validation
            if ($this->contactmodel->validateEmail($email) == FALSE) {
                $json['error']['email'] = 'Please enter valid email address';
            // check conatct no validation
            if($this->contactmodel->validateMobile($contactNo) == FALSE) {
                $json['error']['contactno'] = 'Please enter valid contact no. format: 9000000001';
            // note validation
                $json['error']['note'] = 'Please enter your enquiry';
                try {
                 $last_id = $this->contactmodel->create();
                } catch (Exception $e) {
                if (!empty($last_id) && $last_id > 0) {
                    $json['status'] = 'success';
        echo json_encode($json);



if (!defined('BASEPATH')) exit('No direct script access allowed');

class Contactmodel extends CI_Model {
    private $_name;
    private $_email;
    private $_contactNo;
    private $_note;
    private $_enquiry;
    public function setName($name) 
        $this->_name = $name;
    public function setEmail($email)
        $this->_email = $email;
    public function setContactNo($contactNo) 
        $this->_contactNo = $contactNo;
    public function setNote($note)
        $this->_note = $note;
    public function setEnquiry($enquiry) 
        $this->_enquiry = $enquiry;
    // save value in database
    public function create()
        $data = array(
            'name' => $this->_name,
            'email' => $this->_email,
            'contactno' => $this->_contactNo,
            'note' => $this->_note,
            'enquiry' => $this->_enquiry,
        $this->db->insert('contactenq', $data);
        return $this->db->insert_id();
    // email validation
    public function validateEmail($email)
        return preg_match('/^[^\@]+@.*.[a-z]{2,15}$/i', $email)?TRUE:FALSE;
    /* mobile validation
    public function validateMobile($mobile)
        return preg_match('/^[0-9]{10}+$/', $mobile)?TRUE:FALSE;

Also separately, is there an easier way to debug codeigniter. I used to use the PHP error log when i was doing procedural but i cant find the same function with CI.

Thank you in advance.

PHP errors.log still works, ensure error_reporting(-1); is set and is not turned off.

Also CodeIgniter has it’s own logging system, depending on the version it is most l likely to be found in the app/config.php file. Search for the log file permissions of 0644 and change to 0777. Also note the error log level which is best set to maximum while debugging. Delete the log file, run application then check both error logs.

Tapped on a tablet :frowning:

Perfect, thanks John, i set the log threshold to 3 and it seems to throw a load of info into a file which is handy but unfortunately stops at file loaded: …header.php so i can see that the script is running but getting stuck at loading the page. I just can’t see the wood through the trees on how to correct the issue.

Still at least im now seeing some error logs. Thanks John.

1 Like

Solved, i knew it was something simple… DOH!

It was under the pages folder which i thought i had already tried but clearly not.

1 Like

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.