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