private function runModule() { switch ($this->sModule) { case "Home": $oController = new HomeController(); $oController->run($this->sAction, $this->asArgs, $this->sView); break; case "ShowRoom": $oController = new ShowRoomController(); $oController->run($this->sAction, $this->asArgs, $this->sView); break; case "Basic": $oController = new BasicController(); $oController->run($this->sAction, $this->asArgs, $this->sView); break; case "Products": $oController = new ProdutosController(); $oController->run($this->sAction, $this->asArgs, $this->sView); break; default: echo "Erro: Módulo não existe"; } /* switch ( $this->sModule ) */ }
<?php set_include_path(implode(PATH_SEPARATOR, array(realpath(dirname(__FILE__) . '/library'), get_include_path()))); require_once 'Slim/Slim.php'; require_once 'controller/ProdutosController.php'; $app = new Slim(); $pcontroller = new ProdutosController(); $app->get('/produtos', function () use($pcontroller) { echo json_encode($pcontroller->listarProdutos()); }); $app->post('/produtos', function () use($pcontroller, $app) { $produto = json_decode(file_get_contents("php://input")); echo json_encode($pcontroller->salvarProduto($produto)); }); $app->put('/produtos', function () use($pcontroller, $app) { $produto = $app->request()->put(); unset($produto['$$hashKey']); echo json_encode($pcontroller->atualizarProduto($produto)); }); $app->delete('/produtos/:id', function ($id) use($pcontroller) { echo $pcontroller->removerProduto($id); }); $app->run();