After doing insert, redirect to the listing of records in Kohana

2

I started working with Kohana yesterday and there was a problem here.

My default Controller is the "page" and the action is "home". On the "page" controller I have these functions here to set up the layout:

class Controller_Page extends Controller_Index {

 public function action_home(){
     $this->template->title = "Helpdesk";
     $this->template->content = View::factory('home');
 }
 public function action_newClient(){
     $this->template->title = "Helpdesk";
     $this->template->content = View::factory('newClient');
 }
 public function action_listClient(){
     $this->template->title = "Helpdesk";
     $this->template->content = View::factory('listClient');
 }
}

I also have a Controller named "client" and inside it these functions:

class Controller_Client extends Controller_Template {
//put your code here
public function action_novo(){
    $cliente = ORM::factory('cliente');        
    $cliente->nomeCliente = $this->request->post('nomeCliente');
    $cliente->cnpjCliente = $this->request->post('cnpjCliente');
    $cliente->dataCadastro = date("Y-m-d H:i:s");
    if($cliente->save()){
        $session = Session::instance();
        $session->set('msg', 'Cliente cadastrado com sucesso!');
        $this->redirect('page');            
    }

}
public function action_lista(){
    $cliente = ORM::factory('cliente')->find_all();
    $view = View::factory('listClient');
    $view->set('clientes',$cliente);
    $this->response->body($view);
}
}

In the template that you are putting together, I have a link that points to a form, which in this case is the action_newClient function of the controller page where a client is registered, it works fine. In this form, in the action I'm pointing it to the method action_novo of controller Client .

How can I redirect to a screen that shows all the results?

>     
asked by anonymous 27.02.2014 / 23:35

1 answer

1

So I understand that you searched the database for all the data in the 'customer' table and there in the

  

$ view-> set ('clients', $ client);

Now is your var in the view to show the infos is the 'clients' you do not actually call the method because you are already in the corresponding view.

    
10.05.2014 / 02:44