i am working on a voting section of my website built over Yii framework,i am using ajax to call a php script that should load an Answer model and increment the positive/negative vote,however this script cant access model Class of Answers,if i use require_once('Answer.php') it gives me ActiveRecord.php Class not found,..my script file is not a Class so i cant extend ActiveRecord Class ,i am wondering if there is a way i can load Answer model in my script without messing around with Yii code,i am a newbie on yii,Thanks
here is my js
function downVoteAnswer(id){
var data= $.get("/codepacu/protected/models/votehandler.php",function(data){
$('#ans-downvote-'+id).text(data);
});
}
Here is my php script file
require_once('Answer.php');
$model=Answer::loadModel(4);
$model->up_vote=$model->up_vote++;
$model->save();
echo $model->up_vote;
This error is nothing specific to Yii, it is so with any PHP code:
You can only use a class when it’s definition is available. In your case, the definition is only loaded partly. You already load the file
Answer.phpfor theAnswermodel class, but that class is defined in more than one file.So this requires you more files to load. Identify all needed classes and require the related files.
This can be a lot, so it is normally better to create some ajax controller endpoint within Yii itself.