代码点火器 - 在我的视图中回显我的数组中的变量

Im a designer that i´m taking my first steps on the programing área, mostly on PHP / MySQL. Past week i need to add a blog section on a page made with code igniter.

I make the secction that show all post in order (title and published date). I made a view that takes the id to show the content. But i can`t echo any of the variables.

When i use var_dump or print and it takes all the variables without any problem.

Did i miss somehting? :(

Thank you.

Model:

class blog extends CI_Model { 

    public function get($id){
         $this->db->select('id, title, description, icon, uri, published_at');
         $this->db->from('blogs');
         $this->db->where('id', $id);
         $query = $this->db->get();
         $data  = $query->result();
         return $query->result();
    if(!empty($data)){
    return $this->make_groups($data);
}
}
}

Controller:

Class Pages extends CI_Controller {

    public function blog_detail($id) {

        $this->load->model('blog');

        if($data = $this->blog->get($id)) {

            $this->load->model('blog');
            $this->data['blog_menu'] = TRUE;
            $this->data['blog'] = $data;

            $this->data['og'] = array(
                'description' => 'INFO',
                'image' => site_url('assets/images/og/blog.png')
            );

          # layout config

            $this->layout->add_css(site_url('assets/css/blog.css'));
            $this->layout->title_for_layout = "TITLE";
            $this->layout->meta = array(
                array('name' => 'description', 'content' => 'DETAIL'),
                array('name' => 'keywords', 'content' => 'KEYWORDS'),
            );

            $this->layout->render('pages/blog_detail/index', $this->data);

        }
    }
}

View:

<?php var_dump($this->data);
echo $blog->published_at; ?>

On your model you are not returning the result

Check that the filenames and class names only have the first letter upper case.

Blog_model.php

class Blog_model extends CI_Model { 

    public function get($id) {
        $this->db->select('id, title, description, icon, uri, published_at');
        $this->db->from('blogs');
        $this->db->where('id', $id);
        $query = $this->db->get();

        return $query->row_array();
    }
}

Controller

controllers > Pages.php

class Pages extends CI_Controller {

   public function __construct() {
       parent::__construct();
       $this->load->model('blog_model');               
   }

    public function blog_detail($id) {

        $blog_data = $this->blog_model->get($id);

        if($blog_data)) {


            $this->data['blog_menu'] = TRUE;

            $this->data['published_at'] = $blog_data['published_at'];

            var_dump($blog_data);

            $this->data['og'] = array(
                'description' => 'INFO',
                'image' => site_url('assets/images/og/blog.png')
            );

          # layout config

            $this->layout->add_css(site_url('assets/css/blog.css'));
            $this->layout->title_for_layout = "TITLE";
            $this->layout->meta = array(
                array('name' => 'description', 'content' => 'DETAIL'),
                array('name' => 'keywords', 'content' => 'KEYWORDS'),
            );

            $this->layout->render('pages/blog_detail/index', $this->data);

        }
    }
}

View

<?php echo $published_at;?>