I have created a plugin which brings a record from db table. Now I want to display the record into the page. I am trying to use tags but unable to get it working. How can I do that?
Here is the detail:
Plugin
class Plugin_News extends Plugin
{
function getNewsDetails()
{
$this->load->model('news/news_m');
$result = $this->news_m->getNews();
return $this->attribute('result',$result);
}
}
Model
public function getNews()
{
$id = isset($_REQUEST['id']) ? $_REQUEST['id'] : 0;
if($id > 0 )
{
$where = "WHERE id = $id";
}else{
$where = " ";
}
$sql_query =" SELECT
id,
news_title ,
news_description ,
FROM default_news
$where";
$query = $this->db->query($sql_query);
return $query->row();
}
And here is how I am trying to call it
{{ News:getNews }}
<li><a href = "http://localhost/lc/index.php/newsdetail?id={{ id }}">{{ news_title }}</a></li>
{{ /News:getNews }}
And in the page newsdetails to display single record
<tbody>
<tr>
<td>{{ News:getNewsDetails news_title}} </td>
</tr>
<tr>
<td>{{ News:getNewsDetails description }}</td>
</tr>
</tbody>
Its not working and i cant understand the right syntex and found nothing in the documentation clear
Well after a little research i have found this alternative.
In the model return this
return $query->result();
But the query should be limited to 1
SELECT id,news_title , news_description ,FROM default_news $where limit 1
And in the page simply create a loop to display stuff
{{ News:getNewsDetails}}
<tbody>
<tr>
<td>{{ title }}</td>
</tr>
<tr>
<td>{{ description }}</td>
</tr>
</tbody>
{{ /News:getNewsDetails}}
I know this is not perfect but this holds for my requirement.