EllisLab text mark
Advanced Search
     
Message: Undefined index: page_description
Posted: 04 October 2012 04:09 PM   [ Ignore ]
Avatar
Joined: 2012-10-04
3 posts

Hello guys and girls smile
I’m newbie in Codeigniter.

I have table: pages
And when I want to display data from table, I get this error and I don’t know where is my error.

Any suggestions will help me.

A PHP Error was encountered

Severity
Notice

Message
Undefined indexpage_description

Filename
core/Loader.php(829) : eval()'d code

Line Number: 10

" /> 

page_view.php

<!DOCTYPE html>
<
html lang="en">
  <
head>
    <
meta charset="utf-8">
    <
title><?=$pages_info['page_title'];?></title>
    <
meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <
meta name="description" content="<?=$pages_info['page_description'];?>" />
    <
meta name="keywords" content="<?=$pages_info['page_keywords'];?>" /> 

pages_model.php

<?php if (!defined('BASEPATH')) exit('No direct script access allowed');

class 
Pages_model extends CI_Model {

    
function get_pages()
    
{
        $this
->db->where('page_hidden''no');
        
$query $this->db->get('pages');
        return 
$query->result_array();      
    
}
    
    
function get_pages_info($page_title)
    
{
        $this
->db->where('page_title_en'$page_title);
        
$query $this->db->get('pages');
        return 
$query->row_array();
    
}

}

?> 

controllers/pages.php

<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class 
Pages extends CI_Controller {

    
function index()
    
{
        redirect
(base_url());
    
}

    
function page($page_title)
    
{
        $data[
'pages'$this->pages_model->get_pages();
        
$data['pages_info'$this->pages_model->get_pages_info($page_title);
        
$name 'page';
        
$this->template->page_view($data$name);
    
}
    

}

?> 
 
Posted: 04 October 2012 04:55 PM   [ Ignore ]   [ # 1 ]   [ Rating: 0 ]
Joined: 2011-02-23
882 posts

You’re missing the most important part: the controller’s code. Please post this as well because probably no-one can see the error without looking into your controller wink

 Signature 

ignited Community Framework (WiP)  |  Read the User’s Guide. It won’t bite.

STOP! Before posting your questions, remember the WWW Golden rule:
What did you try? What did you get? What did you expect to get?

CI example .htaccess

 
Posted: 04 October 2012 05:08 PM   [ Ignore ]   [ # 2 ]   [ Rating: 0 ]
Avatar
Joined: 2012-10-04
3 posts

Thanks PhilTem for quick reply wink

 
Posted: 04 October 2012 07:52 PM   [ Ignore ]   [ # 3 ]   [ Rating: 0 ]
Avatar
Joined: 2009-02-19
3801 posts

And there is a ‘page_description’ column in the ‘pages’ table?

 Signature 
 
Posted: 05 October 2012 02:58 AM   [ Ignore ]   [ # 4 ]   [ Rating: 0 ]
Avatar
Joined: 2012-10-04
3 posts
CroNiX - 04 October 2012 07:52 PM

And there is a ‘page_description’ column in the ‘pages’ table?

Yes,

table: pages

page_ID
page_title
page_description
page_keywords
page_content

 

 
Posted: 05 October 2012 08:36 AM   [ Ignore ]   [ # 5 ]   [ Rating: 0 ]
Joined: 2011-06-29
18 posts

I’m used to check if my DB driver return anything or not before sending the data to controller.
So i can handle that excepcion without having a error page in frontend.

Example:

function get_pages_info($page_title)
    
{
        $this
->db->where('page_title_en'$page_title);
        
$query $this->db->get('pages');
        return 
$query->row_array();
    

changed to:

function get_pages_info($page_title)
    
{
        $this
->db->where('page_title_en'$page_title);
        
$query $this->db->get('pages');
        if (!empty(
$query) && $query->num_rows() > 0) return $query->row_array();
        return 
false;
    

So now in your controller can handle $variable === FALSE if your query failed or your recordset is empty.

 
Posted: 05 October 2012 08:58 AM   [ Ignore ]   [ # 6 ]   [ Rating: 0 ]
Joined: 2011-02-23
882 posts

You could make that code better readable by using

return $query->num_rows() ? $query->row_array() : FALSE

You don’t need to check for empty($query) since it will always be different from NULL if your query was ran successfully (i.e. there were no MySQL-syntax errors)

 Signature 

ignited Community Framework (WiP)  |  Read the User’s Guide. It won’t bite.

STOP! Before posting your questions, remember the WWW Golden rule:
What did you try? What did you get? What did you expect to get?

CI example .htaccess