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
Can i return a string back to index.php from a controller?
  • Hey , First off I want to thank the Kohana dev team for creating such a good framework. I'm new to kohana and in general to the concept of frameworks and MVC.

    Basically , I am using kohana 3.3 as a backend framework for my android app.

    From index.php , I am creating a request to a controller. The controller works out its logic and gets an string containing a XML Document. I want to return this string back to index.php so that I can echo it.

    This is necessary because, in android , I am capturing whatever the backend echo's (in xml format).

    so is there a way to do this?

    I'm a noob to kohana and this forum, so forgive me if I've asked something extremely stupid.

    Thanks in advance.

  • class Controller_Index extends Controller {
    
        public function action_index()
        {
            // Your logic and calculate string and set to $xml
    
            $this->response->body($xml);
        }
    }
    

    Is that what you're after?

  • And maybe add this line too: $this->response->headers("Content-Type", "text/xml");

  • I think he is talking about a sub-request? Try the code below ... sometimes it gets strange when you are doing a request from inside kohana to another kohana controller

    class Controller_Index extends Controller {
    
        public function action_index()
        {
            $request = Request::factory('http://domain.com/some/other/controller');  
            $response = $request->execute(); // controller returns xml
            $this->response->headers("Content-Type", "text/xml"); // set the header
            $this->response->body($response); // return the xml back from index.php
        }
    }
    
  • @chrisgo @nickg @Jack Thanks a lot guys!!

    Your solutions worked for me!

    Thanks for your time! Cheers!

Howdy, Stranger!

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

In this Discussion