Chapter 7: Improving the Dashboard
204
function csv2db(){
unset($_POST[‘submit’]);
unset($_POST[‘csvgo’]);
foreach ($_POST as $line = > $data){
if (isset($data[‘id’])){
$this- > db- > where(‘id’,$data[‘id’]);
unset($data[‘id’]);
$this- > db- > update(‘products’,$data);
}else{
$this- > db- > insert(‘products’,$data);
}
}
}
At the moment, you haven ’ t added any checks in this process to protect the database from badly
composed headers or field names that don ’ t exist. All of these issues will be addressed in the security
chapter.
As usual, the most complicated part of the entire process seems to be the view. The model and controller
functions were very easy to put together. This is just another example of CodeIgniter providing power
and flexibility without extreme complexity.
It ’ s time for another client review.
The Client Review
When you walk Claudia through the new work you ’ ve done, she ’ s ecstatic. She admits that the import
and export features are rudimentary, but that they provide her with more than enough functionality to
get started.
As pleased as you are with her reaction, you still need answers to various important questions.
“ Claudia, I have some questions for you. These questions seem simple, but they ’ re important to answer
now before the site goes live. ”
“ Go ahead, ” Claudia says, shrugging her shoulders.
So far, you ’ ve been able to handle just about everything that ’ s come up, so you ’ ve built up a lot of good
will and trust.
“ The first question has to do with deleted categories, ” you say. “ The system isn ’ t really deleting
categories, of course, just setting their status to ‘ inactive. ’ However, any top - level category that is
inactive won ’ t show any subcategories, even if they are live. And any products assigned to an inactive
subcategory are also not going to show up on the site. ”
“ I think it makes sense to keep live subcategories hidden if a top - level category is made inactive, ”
Claudia says. “ That way I can choose to hide an entire section of the site if there are problems, or if we ’ re
working on a bunch of price changes. ”