Professional CodeIgniter, Thomas Myer
Chapter 7: Improving the Dashboard
209
You ' re not done yet, though. You still need to create the MProducts function
reassignProducts()
.This
function pulls the
category_id
from the incoming form POST data and converts the orphans session
array into a comma - delimited list. From that you can create a
WHERE...IN
clause and update the
Products table.
function reassignProducts(){
$data = array(`category_id' =
>
$this-
>
input-
>
post(`categories'));
$idlist = implode(",",array_keys($this-
>
session-
>
userdata(`orphans')));
$where = "id in ($idlist)";
$this-
>
db-
>
where($where);
$this-
>
db-
>
update(`products',$data);
}
Notice that this
reassignProducts()
function goes in the MProducts model. Even though you ' ve been
working with MCats for a while, don ' t be fooled. Keep related functions together -- in this case, the
relationship is with the database table products.
relationship is with the database table products.
When you test this new workflow, you should see a message on the categories index that confirms the
actions taken -- in this case, the category was deleted, and its products were reassigned. The screen
should look something like Figure 7 - 9 .
Figure 7-9
c07.indd 209
c07.indd 209
6/10/08 5:36:45 PM
6/10/08 5:36:45 PM