Created
September 13, 2013 15:44
-
-
Save Bolinha1/6552393 to your computer and use it in GitHub Desktop.
Brincando com Silex micro-framework PHP, realizando testes de interação com Controllers e métodos de rotas POST e GET.
Exemplo ficticio para aplicação didática.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| // dir myapp/web/index.php | |
| require_once __DIR__.'/../vendor/autoload.php'; | |
| use Silex\Application; | |
| use Symfony\Component\HttpFoundation\Request; | |
| class ControllerApp | |
| { | |
| public function indexAction() | |
| { | |
| $form = "<form action='index.php/inserir' method='post'> | |
| <input type='text' name='nome' placeholder='DIgite seu nome'> | |
| <input type='submit' value='enviar'> | |
| </form> | |
| "; | |
| return $form; | |
| } | |
| public function inserir(Request $request) | |
| { | |
| $nome = $request->get('nome'); | |
| return $nome; | |
| } | |
| } | |
| $app = new Application(); | |
| $app->get('/', 'ControllerApp::indexAction'); | |
| $app->post('/inserir', 'ControllerApp::inserir'); | |
| $app['debug'] = 'true'; | |
| $app->run(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment