Search code examples
postrequestkohanainternal

Internal data post [Kohana 3.1]


In Kohana 3.1.x framework.

What are the benefits to send data with internal requests like this

$post = Request::factory('module/data')
        ->method(Request::POST)
        ->post(array('some' => 'random data'))
        ->execute()
        ->response;

if you could simply send data like this

Module::instance()->data(array('some' => 'random data'));

In this example Module is a random module and data is some random method.

I'll call this Module via ajax and internal requests. I'm planning to design RESTful API.

QUESTION IS: Why use HMVC instead of just directly using an internal class API


Solution

  • Because they're internal requests, there is no additional HTTP request being made.

    You might want to take a look at Request_Client_Internal and compare it to Request_Client_External. After that you should feel enlightened :)

    Edit:

    You should know that AJAX requests aren't the only "external HTTP requests". cURL, PECL HTTP, file_get_contents() and other PHP functions will also send an external HTTP request (imho you should read the RFC 2616 to understand how HTTP actually works).