Welcome Guest, Not a member yet? Register   Sign In
Codeigniter Message: Undefined variable: infos why cant I connect the abouts table?
#11

[eluser]ytsejam[/eluser]
Code:
class About_model extends CI_Model {
function getAll() {
  $q = $this->db->get('abouts');
  if($q->num_rows() > 0){
  foreach ($q->result() as $row)
  {
   $data[] = $row;
  
   }
  return $data;
}
}
}

This is my about_model. Can it something related to ajax?
Ajax.js:
Code:
$(document).ready( function() {

$("#sidebar-content ul li a").click( function(e){
     e.preventDefault();
     $('#page').load(this.href);
     return false;
});

});
#12

[eluser]theprodigy[/eluser]
[quote author="ytsejam" date="1344198342"]
Code:
class About_model extends CI_Model {
function getAll() {
  $q = $this->db->get('abouts');
  if($q->num_rows() > 0){
  foreach ($q->result() as $row)
  {
   $data[] = $row;
  
   }
  return $data;
}
}
}
[/quote]

It looks like you are only returning something from this function if there are rows. Is it possible that it's returning nothing? Have you tried running print_r on the return of this function?
#13

[eluser]ytsejam[/eluser]
This is my services_model
Code:
class Services_model extends CI_Model {

function getAll() {
  $q = $this->db->get('services');
  if($q->num_rows() > 0){
  foreach ($q->result() as $row)
  {
   $data[] = $row;
  
   }
  return $data;
}
}
When I use pre code for the about model. I cant get no answer for the infos. But if I use $records value , It shows me services table.
This is my last edit in thethe about_model It was supposed to load the table abouts. but I think there is an error:
Code:
public function view($page = 'about')
  {
   $this->load->model('about_model');
   $this->load->helper('text');
   $this->data['infos']= $this->about_model->getAll();
   if ( ! file_exists('application/views/pages/'.$page.'.php'))
   {
    // Whoops, we don't have a page for that!
    show_404();
   }
   $data['title'] = ucfirst($page); // Capitalize the first letter
   $this->render_page('pages/'.$page,$data);
[code]
#14

[eluser]theprodigy[/eluser]
Quote:
Code:
class About_model extends CI_Model {
    function getAll() {
        $q = $this->db->get('abouts');
        if($q->num_rows() > 0){
            foreach ($q->result() as $row)
            {
                $data[] = $row;
            }
            return $data;
        }
    }
}
Try changing your getAll function to
Code:
class About_model extends CI_Model {
    function getAll() {
        $q = $this->db->get('abouts');
        $data = array();
        if($q->num_rows() > 0){
            foreach ($q->result() as $row)
            {
                $data[] = $row;
            }
        }
        return $data;
    }
}
After making that change, try running print_r on it again and see what happens.
#15

[eluser]ytsejam[/eluser]
I found something.
This is my routes.php
Code:
$route['default_controller'] = 'home/view';
$route['(:any)'] = 'home/view/$1';
$route['404_override'] = '';
I think it blocks other controllers connecting to database? How can I edit the routes for home and about page or index page?

EDIT :
I solved it by changing :

Code:
$route['default_controller'] = 'home/view';
$route['(:any)'] = 'home/view/$1';
$route['about'] = 'about/view';
$route['404_override'] = '';




Theme © iAndrew 2016 - Forum software by © MyBB