how can I get post data in Kohana 3 controller?
Asked Answered
M

3

10

I've got a view with a form, so when user submits it - could anyone give me a link or a simple example of code Documentation and tutorials for Kohana 3 are so poor against CI .

Michaella answered 1/3, 2011 at 21:45 Comment(0)
B
6

Another way to access post data in Kohana

$username = Arr::get($_POST, 'username', 'default_username');
Bombacaceous answered 2/3, 2011 at 6:56 Comment(0)
F
38

In Kohana 3.1 you should use Request->post():

Request::current()->post()

or if in your controller:

$this->request->post()

Since Kohana is HMVC, you can call sub-requests with dedicated post data, so using the superglobal $_POST is discouraged, since it's not unique to the request.

Flavouring answered 2/3, 2011 at 14:35 Comment(2)
Also you can use $this->request->post($key) to get $_POST[$key] if existsBarram
Although it isn't relevant to this question, I came here looking for request data in general regarding Kohana, and I discovered that $this->request->query() is the GET version of post() and just thought I'd mention it for anyone in my situation. :)Quiles
B
6

Another way to access post data in Kohana

$username = Arr::get($_POST, 'username', 'default_username');
Bombacaceous answered 2/3, 2011 at 6:56 Comment(0)
L
3
       function action_add()
   {
    $tpl =& $this->template;

    // Add companies
    $company_orm = ORM::factory('company');
    $company_orm->values($_POST);

    if ( $company_orm->check() )  //Validation Check
    {
        if ( $company_orm->save() )
        {
            // Inserting data
        }
        else
        {

            // Error
        }
    }
    else
    {
            // Validation Failed
    }

}

Small Example. You can implement all the validations in the model using protected.

Thank you

Litharge answered 9/3, 2011 at 6:38 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.