开发者

how can I get post data in Kohana 3 controller?

开发者 https://www.devze.com 2023-02-14 17:51 出处:网络
I\'ve got a view with a form, so when user 开发者_Go百科submits it - could anyone give me a link or a simple example of code

I've got a view with a form, so when user 开发者_Go百科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 .


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.


Another way to access post data in Kohana

$username = Arr::get($_POST, 'username', 'default_username');


       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

0

精彩评论

暂无评论...
验证码 换一张
取 消