Doubt with Routes and Controllers Laravel 4

3

I'm a beginner in Laravel and I'm having a problem with routes and controllers. I created a form with the following action:

{{ Form::open(array('action' => 'MatriculasController@formulario' }}

I created a route for this action:

Route::post('formulario', 'MatriculasController@formulario');

The form method of the MatriculaController does some operations with the data received from the form and should return a View:

    //função que recebe e manipula os dados do formulario
public function formulario(){
    //recebe os dados do formulario
    $ra=$_POST['ra'];
    $aluno=$_POST['nome'];
    $nasc=$_POST['nascimento'];
    $responsavel=$_POST['responsavel'];
    $cpf=$_POST['cpfResponsavel'];  

    //verifica se o RA foi fornecido
    if (strlen($ra>0)){
        $siga = new Siga();
        $consultaRA=$siga->conecta("select NOM_PESSOA from supervisor.PESSOA where COD_PESSOA='$ra'");
        $resultado=mssql_fetch_array($consultaRA);
        $nome=utf8_encode($resultado['NOM_PESSOA']);
        return View::make('confirmaIdentidade');
    }
    .
    .
    .
}

View Confirmation:

@extends('templates.templateVeterano')

@section('conteudo')

teste

@stop()

The problem is that it is not returning this view and I do not understand why. You are returning a blank page with the url / form.

Does anyone know what I might be doing wrong?

    
asked by anonymous 29.10.2015 / 12:24

1 answer

2

Amanda, apparently what returns the blank page in your code is View::make that is within if .

If you do not meet the condition, as it is not returned, then your code will return a blank page.

To verify that this statement is correct, try doing this after if of $ra .

return 'Alguma coisa errada';

If this appears, then the reason stated above is correct.

What can be done - that is what I would do - is to set return View::make out of any condition if . If you need to send an error message, you can do this:

if ($erro) {
     // Como a requisição é post, volta para mesma página
     // com uma mensagem flash na sessão
     return Redirect::back()->with('mensagem', 'Mensagem de erro');
}

return View::make('x');

In view:

@if(Session::has('mensagem'))
   {{ Session::get('mensagem') }}
@endif

Another problem that can cause the blank page in Laravel 4 is the session name mismatch.

For example:

#view_pai
@yield('content')


 #view_filho
   @extend('view_pai')
   @section('content_')
   {{-- Errei o nome de propósito pra demonstrar --}}
   <div>Alguma coisa</div>
   @stop

If you do View::make('view_filho') , nothing will be returned, since you did not set section to the correct value.

    
29.10.2015 / 12:39