CodeIgniter Forums
Codeigniter Message: Undefined variable: infos why cant I connect the abouts table? - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23)
+--- Thread: Codeigniter Message: Undefined variable: infos why cant I connect the abouts table? (/showthread.php?tid=53715)

Pages: 1 2


Codeigniter Message: Undefined variable: infos why cant I connect the abouts table? - El Forum - 08-05-2012

[eluser]ytsejam[/eluser]
Hello ,
I am a novice coder and trying to learn about CI. Now mysite works in the homepage. Site opens , navigation and content splits into both sites. I can use ajax. I use MY_Controller.php :

Code:
function render_page($view) {
    if( ! $this->input->is_ajax_request() )
    {
      $this->load->view('templates/header', $this->data);
    }
    $this->load->view($view, $this->data);

    if( ! $this->input->is_ajax_request() )
    {
     $this->load->view('templates/menu');
     $this->load->view('templates/footer', $this->data);
    }
  }
my home controller :
Code:
public function view($page = 'home')
  {
   $this->load->helper('text');
   $this->data['records']= $this->services_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);
  }

works and I can get the services-table from the database. and I can use it in the view file as :
Code:
<ul class="blog-medium">
&lt;?php foreach($records as $row): ?&gt;
<li>    
<div class="blog-medium-text">
<h1><a href="./post.html">&lt;?php echo $row->title; ?&gt;</a></h1>
<p class="blog-medium-excerpt">&lt;?php  echo $row->content; ?&gt;<br />
<a href="./post.html" class="read_more">Devamını Okumak için &rarr;</a></p>
</div>
&lt;?php endforeach ?&gt;

But when i click about page I cant get the about table . It gives me undefined variable infos.
about controller :
Code:
public function view($page = 'about')
  {
  $this->load->model('about_model');
   $this->load->helper('text');
   $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);
  }

and my about view :

Code:
&lt;?php foreach($infos as $row): ?&gt;
      <h3>
      &lt;?php echo $row->title; ?&gt;</h3>
      &lt;!-- ELEGANT HORIZONTAL LINE --&gt;
      <div class="hr"> </div>
      &lt;!-- NUMBERED LIST --&gt;

&lt;?php echo $row->content; ?&gt;
&lt;?php endforeach; ?&gt;
thank you .


Codeigniter Message: Undefined variable: infos why cant I connect the abouts table? - El Forum - 08-05-2012

[eluser]TWP Marketing[/eluser]
What are the specific errors?


Codeigniter Message: Undefined variable: infos why cant I connect the abouts table? - El Forum - 08-05-2012

[eluser]ytsejam[/eluser]

A PHP Error was encountered

Severity: Notice

Message: Undefined variable: infos

Filename: pages/about.php

Line Number: 3
A PHP Error was encountered

Severity: Warning

Message: Invalid argument supplied for foreach()

Filename: pages/about.php

Line Number: 3



Codeigniter Message: Undefined variable: infos why cant I connect the abouts table? - El Forum - 08-05-2012

[eluser]theprodigy[/eluser]
You are trying to pass in your $data array
Code:
$this->render_page('pages/'.$page,$data);

but your render_page function doesn't accept a second parameter
Code:
function render_page($view) {
...
}



Codeigniter Message: Undefined variable: infos why cant I connect the abouts table? - El Forum - 08-05-2012

[eluser]ytsejam[/eluser]
My home.php view works without any problem .Why is there a problem in about php.?


Codeigniter Message: Undefined variable: infos why cant I connect the abouts table? - El Forum - 08-05-2012

[eluser]theprodigy[/eluser]
Your home controller is setting $this->data, not $data

Code:
$this->data['records']= $this->services_model->getAll();



Codeigniter Message: Undefined variable: infos why cant I connect the abouts table? - El Forum - 08-05-2012

[eluser]ytsejam[/eluser]
Cant it be because there is only one file for the abouts table?I mean there is only one insert for that table?


Codeigniter Message: Undefined variable: infos why cant I connect the abouts table? - El Forum - 08-05-2012

[eluser]theprodigy[/eluser]
I think it has to do with the about page not setting $this->data.


Codeigniter Message: Undefined variable: infos why cant I connect the abouts table? - El Forum - 08-05-2012

[eluser]ytsejam[/eluser]
My new code is here :
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);
  }
But still the same error.


Codeigniter Message: Undefined variable: infos why cant I connect the abouts table? - El Forum - 08-05-2012

[eluser]theprodigy[/eluser]
what is in your about_model->getAll function?