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

[eluser]soup7[/eluser]
i got it working, i can view 'all' news, i can add new articles, but when i click on the 'view article' (to view one news item by itself) i get


404 Page Not Found

The page you requested was not found.


i added the view($slug) to controller (below), and the news 'view' (below also) and updated the routes as directed (also below). any ideas on what may be incorrect? i can view all news but not one by itself...

public 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');
}

>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>

<?php
echo '<h2>'.$news_item['title'].'</h2>';
echo $news_item['text'];
?&gt;

>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>

$route['news/(:any)'] = 'news/view/$1';
$route['news'] = 'news';
$route['(:any)'] = 'pages/view/$1';
$route['default_controller'] = 'pages/view';
#2

[eluser]greedyman[/eluser]
May be your news_model has a problem, as query ...
#3

[eluser]soup7[/eluser]
thanks... this is it (below)- do you see anything (typo/etc)?

&lt;?php
class News_model extends CI_Model {

public function __construct()
{
$this->load->database();
}
public function get_news($slug = FALSE)
{
if ($slug === FALSE)
{
$query = $this->db->get('news');
return $query->result_array();
}

$query = $this->db->get_where('news', array('slug' => $slug));
return $query->row_array();
}
public function set_news()
{
$this->load->helper('url');

$slug = url_title($this->input->post('title'), 'dash', TRUE);

$data = array(
'title' => $this->input->post('title'),
'slug' => $slug,
'text' => $this->input->post('text')
);

return $this->db->insert('news', $data);
}

}
?&gt;
#4

[eluser]greedyman[/eluser]
I have never done like you. Why don't you try my code as below?
Code:
function get_new_products() {
            $this->db->select();
            $this->db->from('product');
            $this->db->order_by('last_update', 'desc');
            $this->db->limit(3);
            
            $query = $this->db->get();
            
            if ($query->num_rows() > 0) {
                foreach ($query->result() as $row) {
                    $data[] = $row;
                }
            }
            
            return $data;
        }

// and in controller file I get it
$data['new_products'] = $this->product_model->get_new_products();
#5

[eluser]InsiteFX[/eluser]
Check your model and see if it is returning a record to you.

#6

[eluser]soup7[/eluser]
greedyman, i'm just using the tutorial's code. i do not know how your code relates.

insiteFX, how do i Check the model and see if it is returning a record?

thanks-
#7

[eluser]soup7[/eluser]
i like the ideas (logic) of checking for variables at different points in execution/etc. and i understand it when passing variables in regular (procedural) html/php via post/get/db-requests/etc, but i am just learning mvc and am not comfortable checking things at certain points, could someone please tell me how to check a model's variable's value before another layer sees it?

thank you-
#8

[eluser]soup7[/eluser]
InsiteFX, i like your quote

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

Input -> Controller | Processing -> Model | Output -> View


where may i read about this as a part of mvc structure, framework, etc- or what ever "mvc" considered to be called.... (that is, in relation to checking variable 'values' at different points).
#9

[eluser]InsiteFX[/eluser]
Code:
$this->db->select();
            $this->db->from('product');
            $this->db->order_by('last_update', 'desc');
            $this->db->limit(3);
            
            $query = $this->db->get();
            
            if ($query->num_rows() > 0)
            {
                // Return data a record was found
            }
            else
            {
                // no record found return error
                return FALSE;
            }

        }
#10

[eluser]greedyman[/eluser]
[quote author="soup7" date="1361820931"]i like the ideas (logic) of checking for variables at different points in execution/etc. and i understand it when passing variables in regular (procedural) html/php via post/get/db-requests/etc, but i am just learning mvc and am not comfortable checking things at certain points, could someone please tell me how to check a model's variable's value before another layer sees it?

thank you- [/quote]

If you are new user with MVC, you should practice some examples about it to start (made by yourself). Read books and watch some tutorials about ASP MVC. ASP MVC and PHP MVC is the same but the approach is difference, we are completely use it to reference. Beside, I else use Java books. And then, you could practice any advanced example. Good luck!




Theme © iAndrew 2016 - Forum software by © MyBB