Professional CodeIgniter, Thomas Myer

Chapter 8: Last-Minute Upgrades
241
The
create()

function checks for POST data. If there is a page name in the POST data, then add the
page using your model function
addPage()

. If there aren ' t any POST data, show the admin_pages_
create view.
function create(){
if ($this-
>
input-
>
post(`name')){
$this-
>
MPages-
>
addPage();
$this-
>
session-
>
set_flashdata(`message','Page created');
redirect(`admin/pages/index','refresh');
}else{
$data[`title'] = "Create Page";
$data[`main'] = `admin_pages_create';
$this-
>
load-
>
vars($data);
$this-
>
load-
>
view(`dashboard');
}
}

The same thing goes for the
edit()

function. If you detect POST data, use
updatePage()

to update the
record in the database. If not, load the admin_pages_edit function and retrieve the appropriate
pages record using the passed - in argument
$id
.
function edit($id=0){
if ($this-
>
input-
>
post(`name')){
$this-
>
MPages-
>
updatePage();
$this-
>
session-
>
set_flashdata(`message','Page updated');
redirect(`admin/pages/index','refresh');
}else{
$data[`title'] = "Edit Page";
$data[`main'] = `admin_pages_edit';
$data[`page'] = $this-
>
MPages-
>
getPage($id);
$this-
>
load-
>
vars($data);
$this-
>
load-
>
view(`dashboard');
}
}

Finally, the
delete()

function takes whatever you pass in as an argument (
$id

) and passes that value to
deletePage()
.
function delete($id){
$this-
>
MPages-
>
deletePage($id);
$this-
>
session-
>
set_flashdata(`message','Page deleted');
redirect(`admin/pages/index','refresh');
}
}//end class
?
>
c08.indd 241
c08.indd 241
6/10/08 5:37:26 PM
6/10/08 5:37:26 PM


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

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

OK

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