I have difficulties trying to call a function even though i have already used "require_once". I'm not sure if the $caseCtrl is even being defined, which could explain the reason why I can't use retrieveAllCaseID() (in create_case.php file).
Here's the flow: create_case.php (user interface/form) -> case_controller.php -> caseDAO.php
This is my error:
Fatal error: Call to undefined method case_controller::retrieveAllCaseID() in \dct\view\create_case.php on line 82
create_case.php file:
require_once(dirname(__FILE__) . '\..\controller\case_controller.php');
$caseCtrl = new case_controller();
$caseCtrl->retrieveAllCaseID(); //this line is calling the error
case_cotroller.php file:
function retrieveAllCaseID() {
$caseDAO = new caseDAO();
$result_array = $caseDAO->retrieveAllCaseID();
return $result_array;
}
caseDAO.php file:
function retrieveAllCaseID() {
$allCaseID = Array();
$dbMgr = new dbManager();
$conn = $dbMgr->getDBConnection();
// peform query
$query = "select case_id from case_report where case_status like '%Follow Up%'";
$result = mysql_query($query);
if (!$result)
{
print "<br />";
die ('(caseDAO.php->retrieveAllCaseID)Error in executing query: '.mysql_error());
}
if (mysql_num_rows($result)==0){
return null;
}
while ($resultSet = mysql_fetch_assoc($result)) {
$allCaseID[]= $resultSet['case_id'];
}
$dbMgr->closeDBConnection($conn);
return $allCaseID;
}//retrieveAllCaseID
I'm aware that there are similar cases here, but I can't seem to find one that really 'answers' my questions.
It seems that if create_case.php file you create an object of case_controller and want to run the method retrieveAllCaseID but in case_controller.php file you have only a declaration of the function, not the class and method.
If you change your create_case.php file into:
require_once(dirname(__FILE__) . '\..\controller\case_controller.php');
$caseCtrl = retrieveAllCaseID(); //this line is calling the error
there wouldn't be this error. However, they might occur other errors because we don't know what you wanted to do in your application.
I also assume in this answer that there is a typo in "case_cotroller.php file:" - because it should be "case_controller.php file:"