Main_model
Main_model is core of blogmer.It contains all important functions.It generates post, page, feed in readable format from database.Let's discuss each function one by one.
Beta: This is an Beta model. It can be changed anytime.
Functions:
- SinglePostView($id,$full=false,$title="",$checktitle=false)
- PageLinks()
- SinglePage($URLTitle)
- categories($cat,$title,$id)
- archives($date,$id)
- home($posts)
- get_recent_posts($number=10)
$id : represents post id
Main_model Function Reference
$this->Main_model->SinglePostView($id,$full=false,$title="",$checktitle=false)
It takes 4 arguments. Only first one is essential. Rest are optional .It generates an array on the basis of 4 arguments.
We've ||more|| in blog posts so that we can short entry on home page and shows full when required
- $id : It can be number based id or URL Tlitle. Last argument decides by default its a numeric id.
- $full : its a value to decides how to deal with ||more|| .By default it leave portion of content after ||more||.
- $title: URL Title data
- $checktitle=If you supply URL Title and not numeric id then set true. By default FALSE.
Array contains:
- $blogmer['date']
- $blogmer['post_title']
- $blogmer['post_status']
- $blogmer['content']
- $blogmer['categories']
- $blogmer['author_name']
- $blogmer['title_link']
- $blogmer['comment_link]
- $blogmer['comment_no']
- $blogmer['total_comments']
- $blogmer['full']
On Error :if id is not found it sets $blogmer['error'] to TRUE with $blomer['description']
$this->Main_model->PageLinks()
Generate li based list containing pages list with relative links.
Example output
<li><a href="blog path/features">Features</a></li>
<li><a href="blog path/blogmer-contact">Contact</a></li> <li><a href="blog path/about-speedovation">About Company</a></li>
I dropped <ul> part so that we add more external links without touching database.
See this example for better understanding.
<ul class="some-custom-class"> <li id="current"><a href="external link">external info</a></li>
<li><a href="blog path/features">Features</a></li>
<li><a href="blog path/blogmer-contact">Contact</a></li> <li><a href="blog path/about-speedovation">About Company</a></li>
<ul>
This section can be found in theme/currenttheme/main.php
$this->Main_model->SinglePage($URLTitle)
Dt takes single arguments. It generates an array on the basis of $URLTitle.
$URLTitle is url title of page
Array contains:
- $blogmer['post_title']
- $blogmer['title_link']
- $blogmer['content']
On Error :if id is not found it sets $blogmer['error'] to TRUE with $blomer['description']
$this->Main_model->categories($cat)
Generate 2d array.
Contains :
- $blogmer[$i]['date']
- $blogmer[$i]['post_title']
- $blogmer[$i]['post_status']
- $blogmer[$i]['content']
- $blogmer[$i]['categories']
- $blogmer[$i]['author_name']
- $blogmer[$i]['title_link']
- $blogmer[$i]['comment_link]
- $blogmer[$i]['comment_no']
- $blogmer[$i]['total_comments']
- $blogmer[$i]['full']
Theme function to grab result from this function. It respect ||more|| .
<?php
for($i=0;$i<count($allposts)-1;$i++)
{
$comments=base_url().'blog/post/'.url_title($allposts[$i]['post_title']).'#comments'; ?>
<h2><?=$allposts[$i]['title_link'];?></h2>
<p class="post-info">Posted by <?=$allposts[$i]['author_name'];?>
| Filed under <?=$allposts[$i]['categories'];?> </p>
<p><?=$allposts[$i]['content'];?></p>
<p class="post-footer">
<a href="<?=$comments?>" class="comments">Comments : <?=$allposts[$i]['comment_no'];?></a> |
<span class="date"><?=$allposts[$i]['date'];?></span>
</p>
<?php } //end of for loop?>
This section can be found in theme/currenttheme/main.php
$this->Main_model->archives($date,$id)
Exaclty above only difference is when we're fetching data from database where condition is changed. For this we compare date basis ouput.
$this->Main_model->home($posts)
Exaclty above only difference is when we're fetching data from database there no condition.
$this->Main_model->get_recent_posts($number=10)
It return data from posts. It uses Active Record get function.This function is used by feed controller.
Final Collection
$this->load->model('Main_model');
$this->Main_model->SinglePostView($id,$full=false,$title="",$checktitle=false);
$this->Main_model->PageLinks();
$this->Main_model->SinglePage($URLTitle);
$this->Main_model->categories($cat,$title,$id);
$this->Main_model->archives($date,$id);
$this->Main_model->home($posts);
$this->Main_model->get_recent_posts($number=10);