TIP: Use Markdown or, <pre> for multi line code blocks / <code> for inline code.
These forums are read-only and for archival purposes only!
Please join our new forums at discourse.kohanaframework.org
Request view after fetching post
  • Within the same controller I am passing the post data:

    $post = Request::factory('check/result')
                            
            ->method(Request::POST)
            ->post(array('results' => $post))
            ->execute();
    

    I am fetching it in another function:

    $post = Request::current()->post();
    

    Is it possible to switch to the new view and render fetched post?

  • Hi, anything is possible, but quite incomplete question. What are you going to achieve?(and the version of Kohana you are using)

    From Kohana > 3.1: By calling execute() you receive Response object. You can replace $this->response in your controller with the one you obtained. But if you are using something like Controller_Template then the $this->reponse->body() will be overwritten by data from specified template in after() method of the controller, but you can suppress this behavior by setting $this->auto_render=FALSE . Without more details I am not able to help.

  • Hi,

    thanks. I am using Kohana 3.2 and I do have Controller_Template.

    As I said in the same controller I am passing the POST data between functions. But the second does not pick up its own view, it renders the one attached to the first function.

    So I am kind of stuck. I know how to replace the post method with the session method, but it's just my curiosity now, that keeps me here.

    thank you

  • As I understand your intent, you are doing something like this.

    class Controller_Check extends Template_Controller {
      public function action_save(){
         $post = Request::factory('check/result')                        
            ->method(Request::POST)
            ->post(array('results' => $post))
            ->execute();
          //now the $post is an instance of Response with body rendered by template.
          $result = $post->body(); //rendered from template.  Therefor $result =='Result'
      }
    
      public function action_check(){
          $post = $this->request->post();  // same as Request::current()->post();
          //after the call from action_save here is an array('results'=>Request::initial()->post());
          //do some action    
          $this->template->content = 'Result'; // let's assume the template view is only doing  echo $content;      
      }   
    }
    

    If you want to modify post data in action_check, you have to return the modified data in body (for. ex. via JSON). If you are doing something else post the core of your code. What are you passing in, what are you expecting to get...

  • I will check it out. Thank you.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

In this Discussion