1
The server log reported the following error:
Notice:
Undefined variable: app in C: xxxx api v1 routers Schedule.php on line 28
Fatal error:
Call to a Member Function get() on null in /home/xxx/public_html/projects/xxx/api/v1/routers/Schedule.php on line 22
The code is organized as follows:
Route class:
use xxx\API\API_Schedule;
use xxx\model\Schedule;
use Slim\Http\Request;
use Slim\Http\Response;
$app->get('/schedule', function (Request $request, Response $response, $args ){
$delivery_id = $request->getParam('deliveryman_id');
$api = new API_Schedule();
$resposta = $api->getSchedules($delivery_id);
$response->write($resposta);
});
$app->post('/schedule/deny/{id}', function(Request $request, Response $response, $args){
$deliveryman_id = $request->getParam('deliveryman_id');
$schedule_id = $args['id'];
$api = new API_Schedule();
$response->write($api->denySchedule($deliveryman_id, $schedule_id));
});
$app->post('/schedule/accept/{id}', function(Request $request,Response $response, $args){
$deliveryman_id = $request->getParam('deliveryman_id');
$schedule_id = $args['id'];
$api = new API_Schedule();
$response->write($api->acceptSchedule($deliveryman_id, $schedule_id));
});
$app->post('/schedule/accept', function(Request $request,Response $response, $args){
$deliveryman_id = $request->getParam('deliveryman_id');
$api = new API_Schedule();
$data = $api->scheduleAccepted($deliveryman_id);
if($data!= false){
$response->write($data);
}
});
$app->post('/schedule', function (Request $request, Response $response, $args ){
$schedule = new Schedule();
$schedule->name = $request->getParam('name');
$schedule->date_to = $request->getParam('date_to');
$schedule->min_deliveryman = $request->getParam('min_deliveryman');
$schedule->max_deliveryman = $request->getParam('max_deliveryman');
$schedule->status = 0;
$schedule->client_id = $request->getParam('client_id');
$schedule->daily_price = $request->getParam('daily_price');
$schedule->delivery_price = $request->getParam('delivery_price');
$api = new API_Schedule();
$response->write($api->addNewSchedule($schedule));
});
Index class:
<?php
use Slim\App;
require (__DIR__.'/../../vendor/autoload.php');
session_start();
$app = new App();
include (__DIR__.'/routers/Schedule.php');
$app->run();
The error is strange because this is not the only existing route, however it is the only one returning this error, thanks in advance.
You can ask the question the full code of the file
routers/Schedule.php
? The mistake could be somewhere else.– Woss
added, thank you.
– wagnermps