I'm trying to develop an application on code igniter framework. My question is when I wrote the model of my application it grew large, so I broke it down into two separate file. The main files merely calls the other one using include command. The problem is that the calling file dumps the script in the called file in plain text on the web browser.
my model file looks like this :
<?php
defined('BASEPATH') or exit('No direct script access allowed');
class Admin_model extends CI_Model{
public function __construct(){
parent::__construct();
$this->load->database();
}
public function return_admin_dashboard_articles($priviledge_id,$by_author=null,$date_published=null){
$index = 0;
$query_articles = null;
//fetching list of articles
include 'includes/posts_query.inc.php';
return $data;
}
}
?>
and the file posts_query.inc.php looks like this:
<?php>
if($priviledge_id==1 || $priviledge_id==2){
$this->db->select('articles.id,articles.title,articles.summary,users.user_name,date(articles.pub_date) as
pubs_date,articles.author');//add date and time stamp to the table
$this->db->from('articles');
$this->db->join('users','articles.author=users.user_id');
if($by_author and $date_published==null){
$this->db->where('articles.author',$by_author);
}
else if($by_author=='all' and $date_published){
$this->db->where('date(articles.pub_date)=',$date_published);
}
$this->db->where('users.user_priviledge_id=',$priviledge_id); //change this to user_priviledge_id>$priviledge_id to see articles by all the users
$query_articles = $this->db->get();
}
//echo $query_articles;
else{
$this->db->select('articles.id,articles.title,articles.summary,users.user_name,date(articles.pub_date) as pubs_date,articles.author');//add date and time stamp to the table:done
$this->db->from('articles');
$this->db->join('users','articles.author=users.user_id');
$this->db->where('users.user_priviledge_id=',$priviledge_id);
$query_articles = $this->db->get();
}
if($query_articles->num_rows()>0){
foreach($query_articles->result_array() as $row){
$data['articles'][$index]=array(
'id'=>$row['id'],
'title'=>$row['title'],
'summary'=>$row['summary'],
'author'=>$row['user_name'],
'date'=>$row['pubs_date'],
'author_id'=>$row['author']
//'time'=>$row['time']
);
$index++;
}
}
else{
$data['error']['articles']='Could not fetch articles';
}
?>
The complete posts_query.inc.php file is displayed on the web page. What is the reason behind this? Any help will be much appreciated.
Thanks.
I'm running XAMPP (Apache 2.4.10, PHP 5.6.3,MySql 5.6 CodeIgniter 3.0) on windows 10.