Welcome Guest, Not a member yet? Register   Sign In
A PHP Error was encountered - Message: Undefined index: title
#1

Hello Guys, could someone give a Light please, what i am doing wrong here?

Thanks in Advance!


This is my Post Controller:

Code:
    // LOAD POST INDIVIDUALLY
    public function view ($slug = NULL)
    {
        //******* THE FUNCTIONS MUST BE LOADED IN EVERY METHOD *******//
        // Load the Function php echo base_url();
        $this->load->helper('url');
        // Loading a Model Locally
        $this->load->model('Post_model');
        //******* THE FUNCTIONS MUST BE LOADED IN EVERY METHOD *******//
     
        
         $data['post'] = $this->Post_model->get_posts($slug);

        if(empty($data['post']))
        {
             show_404();
        }

        $data['title'] = $data['post']['title'];                
        
        $this->load->view('templates/header');
        $this->load->view('posts/view', $data);
        $this->load->view('templates/footer');

    }


and this the view file:

Code:
<h2><?php echo $post['posts_title']; ?></h2>

<small class="post-date">Posted on:
    <?php echo $post['posts_date_insertion']; ?>
</small><br>

<div class="post-body">
    <?php echo $post['posts_body']; ?>
</div>

and this is the error message on the browser:

A PHP Error was encountered
Severity: Notice
Message: Undefined index: title
Filename: controllers/Posts.php
Line Number: 59
Backtrace:
File: C:\xampp\htdocs\dogs\application\controllers\Posts.php
Line: 59
Function: _error_handler
File: C:\xampp\htdocs\dogs\index.php
Line: 315
Function: require_once
Reply
#2

The only place in the controller code you show, that references an index "title", is
Code:
$data['title'] = $data['post']['title'];
This must be line 59, no?

The error message suggests that $data['post'], which you get from
Code:
$this->Post_model->get_posts($slug);
is not returning an array with a 'title' element.

This sounds like the problem lies in your Post_model, or in the datait is retrieving.
Reply
#3

(02-18-2019, 09:24 PM)ciadmin Wrote: The only place in the controller code you show, that references an index "title", is
Code:
$data['title'] = $data['post']['title'];  
This must be line 59, no?

The error message suggests that $data['post'], which you get from
Code:
$this->Post_model->get_posts($slug);
is not returning an array with a 'title' element.

This sounds like the problem lies in your Post_model, or in the datait is retrieving.

Thank you so much Mr.Admin....

As solution i just removed the line under and all the things works fine!

Code:
$data['title'] = $data['post']['title'];

Thank you so much for the Light!
Reply
#4

Please, on this Forum, how can i give the Topic as completed or done?
Reply
#5

@Porto,

You can add the following text to the title '[SOLVED]'.
You can also click the +Rate button to give ciadmin credit for helping you.
Reply
#6

(02-19-2019, 07:41 AM)php_rocs Wrote: @Porto,

You can add the following text to the title '[SOLVED]'.
You can also click the +Rate button to give ciadmin credit for helping you.

Thank you @php_rocs! Done!
Reply




Theme © iAndrew 2016 - Forum software by © MyBB