Professional CodeIgniter, Thomas Myer

Chapter 7: Improving the Dashboard
213
function create(){
if ($this-
>
input-
>
post(`name')){
$this-
>
MColors-
>
createColor();
$this-
>
session-
>
set_flashdata(`message','Color created');
redirect(`admin/colors/index','refresh');
}else{
$data[`title'] = "Create Color";
$data[`main'] = `admin_colors_create';
$this-
>
load-
>
vars($data);
$this-
>
load-
>
view(`dashboard');
}
}

Very similar things are in the
edit()

function. Notice the use of the
$id

argument to pull out the
appropriate color from the colors database.
function edit($id=0){
if ($this-
>
input-
>
post(`name')){
$this-
>
MColors-
>
updateColor();
$this-
>
session-
>
set_flashdata(`message','Color updated');
redirect(`admin/colors/index','refresh');
}else{
$data[`title'] = "Edit Color";
$data[`main'] = `admin_colors_edit';
$data[`color'] = $this-
>
MColors-
>
getColor($id);
$this-
>
load-
>
vars($data);
$this-
>
load-
>
view(`dashboard');
}
}
Finally, here ' s the
delete()

function. It also uses
$id

argument to act on the appropriate color ID.
function delete($id){
$this-
>
MColors-
>
deleteColor($id);
$this-
>
session-
>
set_flashdata(`message','Color deleted');
redirect(`admin/colors/index','refresh');
}
}//end class
?
>

Now it ' s time to create your MColors model functions. You ' re going to need
getColor()
,
getAllColors()
,
createColor()
,
updateColor()

, and
deleteColor()

. Because you ' ve built
similar functions in all of your models so far, they ' re shown on the next page without extraneous context.
For a good refresher on how such functions are built, see the section on " Creating the Category
Management Tools " in Chapter 6.
c07.indd 213
c07.indd 213
6/10/08 5:36:46 PM
6/10/08 5:36:46 PM


Другие страницы

 
Cкачать книги бесплатно без регистрации в электронном виде (pdf, chm, txt).Вы можете читать книги онлайн на нашем сайте литературного портала книг.Большая подборка учебников, пособий, интересных книг.Электронные книги на английском языке скачать бесплатно без смс.

OK

Loading...
...
Закрыть