K
K
Konstantin782014-10-30 02:21:12
Kohana
Konstantin78, 2014-10-30 02:21:12

[kohana] What is the best thing to do when saving a record?

Good day, dear forum users:
To get data in the edit form, I use:

$main_dep = DB::select('main_dep_id')
                        ->from('departments')
                        ->where('id', '=', $id);
$one_department_o1 = ORM::factory('department')
                                ->where('id', '=', $id)
                                ->or_where('id', '=', DB::expr('('.$main_dep.')'))
                                ->find_all();

Action result (2 rows) in $one_department_o1:
Database_MySQL_Result Object ( [_internal_row:protected] =>…
I got the required information in the edit window.
But if I want to save the changes in the window (press the save button), then I have to set values ​​use the "values" method (in "ORM")
(ex:
$data = Arr::extract($_POST, array('abbreviation', 'name', 'user_id', 'main_dep', 'status',));
$one_department_o1->values($data)).

But since there was no code in "...\Database\Result.php" of this method, the compiler throws an error:
Call to undefined method Database_MySQL_Result::values()

Question :
I.e.
If the user wants to edit the entry, alternatively, when clicking the save button, will I need to create another model?
if ($this->request->post())    
        {
  $one_department_o2 = ORM::factory('department', $id);
            $data = Arr::extract($_POST, array('abbreviation', 'name', 'user_id', 'main_dep', 'status',));
            $one_department_o2->values($data);
…

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexander Gontarev, 2014-10-30
@igontarev

$one_department_o2->abbreviation = $data['abbreviation'];
...
$one_department_o2->save();

does it work like that?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question