Hi! Sorry my bad english.
The project is a poll system with voting in 'starlets’
I have a problem in my Ajax. I’m using Slim framework with Eloquent
Project on github: https://github.com/noebezerra/survey-slim
I have an ajax (app.twig):
$('.stars-default').click(function(e) {
e.preventDefault();
$.ajax({
url: '../app/routes.php',
type: 'POST',
dataType: 'html',
data: {valor: pointStar, qtdperguntas: qtdperguntas},
})
.done(function(data) {
console.log(data);
})
.fail(function() {
console.log("error");
})
});
It returns me an Array (pointStar) which is the amount of stars
selected for each question and the amount of questions that have in the
poll (qtdperguntas).
Poll.php
<?php
namespace App\Controllers;
use App\Models\PollAnswers;
session_start();
class Poll extends Controller {
public function poll() {
$qtdperguntas = $_GET['qtdperguntas'];
$result = '[';
for ($i=0; $i < $qtdperguntas; $i++) {
if ($i < $qtdperguntas - 1) {
$result .= '"'.$_GET['valor'][$i].'",';
} else {
$result .= '"'.$_GET['valor'][$i].'"';
}
}
$result .= ']';
$userpoll = PollAnswers::where('id_user', '=', $_SESSION['user']);
if (!$userpoll) {
PollAnswers::create([
'id_user' => $_SESSION['user'],
'answers' => $result
]);
echo "insert";
} else {
$userpoll->answers = $result;
echo "update";
}
}
}
?>
Controller.php
<?php
namespace App\Controllers;
class Controller {
protected $container;
public function __construct($container) {
$this->container = $container;
}
public function __get($property) {
if ($this->container->{$property}) {
return $this->container->{$property};
}
}
}
?>
PollAnswers.php
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
class PollAnswers extends Model {
protected $table = 'poll_answers';
protected $fillable = array('id_user', 'id_poll_question', 'answers');
}
?>
When the ajax gets there on the page gives the following error:
Fatal error: Class ‘Controller’ not found in /var/www/html/survey-slim/app/Controllers/Poll.php on line 14, referer: http://localhost/survey-slim/public/
It seems that it does not recognize my class. Does anyone have a
suggestion? As the project is on github feel avontade to contribute =)