Welcome Guest, Not a member yet? Register   Sign In
I cannot reach the title of my forum
#1

I'm trying to create a forum and I have it(more or less) but I cannot reach the title and other elements in the view of the single entrance.
This is the error message that I recieve:

PHP Code:
SeverityWarning

Message
Attempt to read property "title" on null

Filename
forum/single.php

Line Number
7

Backtrace
:

FileC:\xampp\htdocs\logopedas\application\views\forum\single.php
Line
7
Function: _error_handler

File
C:\xampp\htdocs\logopedas\application\controllers\Forum.php
Line
120
Function: view

File
C:\xampp\htdocs\logopedas\index.php
Line
335
Function: require_once 
Here you can see the controller:
PHP Code:
public function index($slug false) {
 
 
// create the data object
 
$data = new stdClass();
 
 if (
$slug === false) {
 
 
// create objects
 
$forums $this->forum_model->get_forums();
 
 foreach (
$forums as $forum) {
 
 
$forum->permalink    base_url($forum->slug);
 
$forum->topics      $this->forum_model->get_forum_topics($forum->id);
 
$forum->count_topics count($forum->topics);
 
$forum->count_posts  $this->forum_model->count_forum_posts($forum->id);
 
 if (
$forum->count_topics 0) {
 
 
// $forum has topics
 
$forum->latest_topic            $this->forum_model->get_forum_latest_topic($forum->id);
 
$forum->latest_topic->permalink $forum->slug '/' $forum->latest_topic->slug;
 
$forum->latest_topic->author    $this->user_model->get_username_from_user_id($forum->latest_topic->user_id);
 
 } else {
 
 
// $forum doesn't have topics yet
 
$forum->latest_topic = new stdClass();
 
$forum->latest_topic->permalink null;
 
$forum->latest_topic->title null;
 
$forum->latest_topic->author null;
 
$forum->latest_topic->created_at null;
 
 }
 
 }
 
 
// create breadcrumb
 // $breadcrumb  = '<ol class="breadcrumb">';
 // $breadcrumb .= '<li class="active">Home</li>';
 // $breadcrumb .= '</ol>';
 
 // assign created objects to the data object
 
$data->forums    $forums;
 
// $data->breadcrumb = $breadcrumb;
 
 // load views and send data
 
$this->load->view('templates/header');
 
$this->load->view('forum/index'$data);
 
$this->load->view('templates/footer');
 
 } else {
 
 
// get id from slug
 
$forum_id $this->forum_model->get_forum_id_from_forum_slug($slug);
 
 
// create objects
 
$forum    $this->forum_model->get_forum($forum_id);
 
$topics  $this->forum_model->get_forum_topics($forum_id);
 
 
// create breadcrumb
 // $breadcrumb  = '<ol class="breadcrumb">';
 // $breadcrumb .= '<li><a href="' . base_url() . '">Home</a></li>';
 // $breadcrumb .= '<li class="active">' . $forum->title . '</li>';
 // $breadcrumb .= '</ol>';
 
 
foreach ($topics as $topic) {
 
 
$topic->author                  $this->user_model->get_username_from_user_id($topic->user_id);
 
$topic->permalink              $slug '/' $topic->slug;
 
$topic->posts                  $this->forum_model->get_posts($topic->id);
 
$topic->count_posts            count($topic->posts);
 
$topic->latest_post            $this->forum_model->get_topic_latest_post($topic->id);
 
$topic->latest_post->author    $this->user_model->get_username_from_user_id($topic->latest_post->user_id);
 
 }
 
 
// assign created objects to the data object
 
$data->forum      $forum;
 
$data->topics    $topics;
 
// $data->breadcrumb = $breadcrumb;
 
 // load views and send data
 
$this->load->view('templates/header');
 
$this->load->view('forum/single'$data);
 
$this->load->view('templates/footer');
 
 }
 
 } 


Here you have the model:

PHP Code:
public function create_forum($title$description) {

        $data = array(
            'title' => $title,
            'slug' => strtolower(url_title($title)),
            'description' => $description,
            'created_at' => date('Y-m-j H:i:s'),
            'updated_at' => date('Y-m-j H:i:s')
        );

        return $this->db->insert('forums'$data);
    
PHP Code:
public function create_topic($forum_id$title$content$user_id) {

        $data = array(
            'title' => $title,
            'slug' => strtolower(url_title($title)),
            'user_id' => $user_id,
            'forum_id' => $forum_id,
            'created_at' => date('Y-m-j H:i:s'),
            'updated_at' => date('Y-m-j H:i:s'),
        );

        if ($this->db->insert('topics'$data)) {

            $topic_id $this->db->insert_id();

            return $this->create_post($topic_id$user_id$content);
        }

        return false;
    


If you miss any other part of the code, just let me know.

Thank you so much for the help.
Reply




Theme © iAndrew 2016 - Forum software by © MyBB