Welcome Guest, Not a member yet? Register   Sign In
Problem with the news tutorial
#1

[eluser]vYN[/eluser]
Hi. I'm new to CI. My problem is that news page is blank. No text at all. Nothing.

I will post my news controller.(ask me if you need more.)

Code:
<?php
class News extends CI_Controller {
    



     function __construct(){
        
         parent::__contruct();
        
         $this->load->model('news_model');
     }
    
    function index(){
        $this->load->model('news_model');
     $data['news'] = $this->news_model->get_news();
     $data['title'] = 'News archive';
    
     $this->load->view('templates/header', $data);
     $this->load->view('news/index', $data);
     $this->load->view('templates/footer');
    }
    
    function view($slug){
    $data['news_item'] = $this->news_model->get_news($slug);

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

    $data['title'] = $data['news_item']['title'];

    $this->load->view('templates/header', $data);
    $this->load->view('news/view', $data);
       $this->load->view('templates/footer');
    }
    
    function create(){
        $this->load->helper('form');
        $this->load->library('form_validation');
        
        $data['title'] = 'Create a news item';
        
        $this->form_validation->set_rules('title', 'Title', 'required');
        $this->form_validation->set_rules('text', 'text', 'required');
        
        if ($this->form_validation->run() === FALSE)
        {
            $this->load->view('templates/header', $data);
            $this->load->view('news/create', $data);
            $this->load->view('templates/footer', $data);
        }
        else
        {
            $this->news_model->set_news();
            $this->load->views('news/success');
        }
    }
}
#2

[eluser]InsiteFX[/eluser]
Code:
|
$this->load->views('news/success');

Remove the s on views
#3

[eluser]vYN[/eluser]
ye ok. But the page is still blank as you can see here: http://sys.homiecraft.org/1/news

but if i comment out:

Code:
function __construct(){
        
         parent::__contruct();
        
         $this->load->model('news_model');
     }

the page works. but does not show news. And on news/create i can't see the form.
#4

[eluser]InsiteFX[/eluser]
I would check your routes below does not look right.

Code:
http://sys.homiecraft.org/1/news
#5

[eluser]vYN[/eluser]
Code:
$route['news/create'] = 'news/create';
$route['news/(:any)'] = 'news/view/$1';
$route['news'] = 'news';
$route['(:any)'] = 'pages/view/$1';
$route['default_controller'] = 'pages/view';
#6

[eluser]CroNiX[/eluser]
The userguide for routes state at the very bottom of the page that the default_controller (and 404_override) need to come before any routes that use regular expressions.
#7

[eluser]vYN[/eluser]
i guess. But it doesn't resovle my issue.
#8

[eluser]CroNiX[/eluser]
It solved another issue you didn't know you had because you haven't discovered it yet. Smile
#9

[eluser]vYN[/eluser]
haha ok ^^
#10

[eluser]InsiteFX[/eluser]
Do a var_dump or print_r to see if your getting any data from your model!




Theme © iAndrew 2016 - Forum software by © MyBB