[eluser]Unknown[/eluser]
Hy everybody. I'm novice in CI and I'm making a site to train. The site works very well with Ajax and JQuery, but I want load the pages from a database instead of a file '.php'. To this I insert the CI on production. I was following the help pages but I had a problem with the function load->model.
I want that the work on this way: I click on menu link, the JQuery sends a ajax request to 'index.php/layout/ajax/' + hash (where
hash is the page to load), the controller layout.php loads the model and returns to JQuery the page requested. The problem starts here, because I think that the CI will make a object with my load->model('Ajax_model) but the return is this:
class Ajax_model extends CI_Model { function Ajax_model() { parent::Model(); } function get($page) { $query = $this->db->query( 'SELECT content FROM pages WHERE pagename="' . $page . '"' ); return $query->result(); } }
Fatal error: Class 'Ajax_model' not found in C:\xampp\htdocs\mySite\system\core\Loader.php on line 303
Code:
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class Layout extends CI_Controller {
public function index()
{
$this->load->helper('url');
//the data array will be filled with database calls
$this->load->view('layout',
$data = array(
'title' => 'NoLimits',
'siteName' => 'NoLimits',
'slogan' => 'Helping You Grow Your Business',
'defaultPage' => 'home'
)
);
}
public function ajax()
{
$page = $this->uri->segment($this->uri->total_segments());
$this->load->model("Ajax_model", "ajax", TRUE);
$this->ajax->get_page($page);
}
}
/* End of file layout.php */
/* Location: ./application/controllers/layout.php */
Code:
class Ajax_model extends CI_Model {
function __construct()
{
parent::__construct();
}
function getPage($page)
{
$query = $this->db->query(
'SELECT content
FROM pages
WHERE pagename="' . $page . '"'
);
return $query->result();
}
}
/* End of file ajax_model.php */
/* Location: ./application/models/ajax_model.php */
I'm crazing about this. Sugestions is extremely welcome.
(Sorry by my bad english)
PS: My CodeIgniter is 2.1.0