I use codeigniter for my project and I am stuck trying to figure it out.
I have javascript that needs to make an AJAX call to retrieve some results based on the dropdown value that was selected.
function fetchLines(){ $.ajax({ url: baseURL + "resources/ajax.php?node=fetchLines", type: 'GET', cache: false, data: { lineType: 'business' }, error: function(err) { alert(err.statusText); }, success: function(data) { console.log(data); } }); }
In this AJAX file, I am trying to turn on my controller and then access the function inside it.
<?php define('BASEPATH', "AJAX"); require_once('../application/controllers/Project.php'); switch($_REQUEST['node']){ case 'fetchLines': $objLines = new Project(); $objLines->fetchLines($_REQUEST['lineType']); break; } ?>
My CI controller then has a private function that I try to call to get the data I need:
private function fetchLines($lineType){ $lines = $this->project_model->fetchLines($lineType); return $lines; }
My goal is for all of my AJAX calls to use an AJAX file or controller (if necessary). It must have access to the controller and return data.
With the current code above, I get the error: Class 'CI_Controller' not found in <b>C:\xampp\htdocs\blueprint\application\controllers \Project.php
Is there a better way to deal with such situations? I am not an OOP specialist, but some readings offer something in this direction.
source share