Class Not Found Error
Posted: Mon Jan 27, 2014 8:40 am
Hello!
Okay I don't know whether this is the right section of the forum where I have posted this question or not. If the latter is the case, I would be happy if the moderators could move it in the appropriate section.
I have created a PHP web project with an HTML page that contains an 'Add' button. The name of the page is awards.html. The awards.html file contains its counterpart JavaScript file, awards.js. A code is executed in this js file when the Add button is clicked. This code sends an AJAX call to a PHP class located in the website root named, example.php. This file contains code to execute a function called, clickFunction() in another file called, Awards.php which is located in the /branding/dataaccesslayer/community/ path of the website folder. This method returns a JSON array to the awards.js page which is displayed in the awards.html page.
The source code of my files is given as follows:
awards.html
awards.js
example.php
Awards.php
The problem here is that the program is throwing me an error in example.php on line number 7 (marked in the code above) which is, Class 'Awards' not found, despite adding a for loop to locate all the files in the folder.
Can anyone please tell me where exactly am I going wrong? Replies at the earliest will be highly appreciated. Thank you in advance.
Okay I don't know whether this is the right section of the forum where I have posted this question or not. If the latter is the case, I would be happy if the moderators could move it in the appropriate section.
I have created a PHP web project with an HTML page that contains an 'Add' button. The name of the page is awards.html. The awards.html file contains its counterpart JavaScript file, awards.js. A code is executed in this js file when the Add button is clicked. This code sends an AJAX call to a PHP class located in the website root named, example.php. This file contains code to execute a function called, clickFunction() in another file called, Awards.php which is located in the /branding/dataaccesslayer/community/ path of the website folder. This method returns a JSON array to the awards.js page which is displayed in the awards.html page.
The source code of my files is given as follows:
awards.html
Code: Select all
<div class = "divbottom">
<div id="divAddAward">
<button class="btn" onclick="onrequest();">Add</button>
</div>
</div>Code: Select all
function onrequest() {
$("#divAddAward").load('example.php');
$.post(
'example.php'
).success(function(resp) {
json = $.parseJSON(resp);
alert(json);
});
}Code: Select all
<?php
foreach (glob("App/branding/data/*.php") as $filename) {
include $filename;
}
$class = new Award(); //Error here!
$method = $class->clickFunction();
echo json_encode($method);
Code: Select all
<?php
class Award extends BaseDocument
{
public function __construct()
{
}
public function clickFunction()
{
$array = array(
'Hello' => 'World!'
);
return $serverarray;
}
}Can anyone please tell me where exactly am I going wrong? Replies at the earliest will be highly appreciated. Thank you in advance.