Professional CodeIgniter, Thomas Myer

Chapter 8: Last-Minute Upgrades
238


Creating the Model

The model for the Pages table should be kept to a bare minimum at this point. All you need are functions
for retrieving one or all pages, for deleting a page, and for adding and updating a page.

As usual, start the model in the classic way. Note that following the earlier pattern, you ' ll call this model

MPages :
<
?php
class MPages extends Model{
function MPages(){
parent::Model();
}
The
getPage()

function pulls out one page from the Pages table, based on ID.
function getPage($id){
$data = array();
$this-
>
db-
>
where(`id',$id);
$this-
>
db-
>
limit(1);
$Q = $this-
>
db-
>
get(`pages');
if ($Q-
>
num_rows()
>
0){
$data = $Q-
>
row_array();
}
$Q-
>
free_result();
return $data;
}
The
getPagePath()

function does the same thing as
getPage()

, except you pass in a path as an
argument. You ' ll be using this function on the Welcome controller to extract one page for a given address.
function getPagePath($path){
$data = array();
$this-
>
db-
>
where(`path',$path);
$this-
>
db-
>
where(`status', `active');
$this-
>
db-
>
limit(1);
$Q = $this-
>
db-
>
get(`pages');
if ($Q-
>
num_rows()
>
0){
$data = $Q-
>
row_array();
}
$Q-
>
free_result();
return $data;
}
c08.indd 238
c08.indd 238
6/10/08 5:37:25 PM
6/10/08 5:37:25 PM


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

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

OK

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