How do I use Kohana ORM's values function when my form field names do not match the table column names?

StackOverflow https://stackoverflow.com/questions/19411130

문제

I'm using Kohana 3.3 ORM and have setup the rules method for validation. Now I would like to actually create a record to my table. I want to populate all the values to my ORM object by calling $ormtable->values($_POST) but my problem is that not all of the field names in the $_POST array exactly match the column name in the table.

For example, my form has a field with the name "billing_address1" but the corresponding table column is "address1".

Is there some existing method in the ORM that does this already? If not, what is the best way to map these alternate field names?

도움이 되었습니까?

해결책

as @kinakero said simply use temp array

$post_array = $_POST;
$post_array['address1'] = $_POST['billing_address1'];
unset($post_array['billing_address1']);

$ormtable->values($post_array);
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top