Welcome Guest, Not a member yet? Register   Sign In
Problem using uri->segment - should be easy....[SOLVED]
#1

[eluser]tinawina[/eluser]
Hi CodeIgniters -

This is totally strange. I'm just trying to throw together a simple rating script. People log in and get the opportunity to rate an article. They click on a graphic -- stars representing a rating of 1, 2, 3, 4, or 5. The URL leads to my ratings controller and looks like this:

http://mysite.org/ratings/name_of_article/1 (if they chose to give a "1" rating)

In my routes.php file I have this setting established:

$route['ratings/:any'] = "ratings/index";

I can't seem to get anything out of $this->uri->segment(3) which would be the rating. I can get the article name from $this->uri->segment(2) with no problem. But where segment(3) is concerned I get this error message:

Fatal error: Call to a member function segment() on a non-object.....

That message refers to the line that tries to assign $this->uri->segment(3) to $this->rating. I'm not sure what's gone wrong -- this always has worked for me just fine before. Any ideas?

Thanks for your help!

Ratings controller:

Code:
class Ratings extends Controller
{
    function __construct()
    {
        parent::Controller();

        // Login check
        if ($this->session->userdata('logged_in') != true) { header("Location: /log/in"); }

        $this->load->model('ratings_data');
        $this->uri = $this->uri->segment(2);
        $this->rating = $this->uri->segment(3);
        $this->screen_name = $this->session->userdata('screen_name');
    }

    function index()
    {
        // check to make sure this user hasn't already rated this article

        $rated_by_user = $this->ratings_data->checkUser($this->uri, $this->screen_name);

        if ($rated_by_user === true)
        {
            redirect ('article/' . $this->uri); // this user already submitted a rating, send back to article
        }
        else // this user hasn't rated this article yet. add to ratings table and send back to article with rating included in tally.
        {
            $update = $this->ratings_data->updateListing($this->uri, $this->rate, $this->screen_name);
            redirect ('article/' . $this->uri);
        }
    }
}


Messages In This Thread
Problem using uri->segment - should be easy....[SOLVED] - by El Forum - 12-15-2007, 12:51 PM
Problem using uri->segment - should be easy....[SOLVED] - by El Forum - 12-15-2007, 02:19 PM
Problem using uri->segment - should be easy....[SOLVED] - by El Forum - 12-15-2007, 04:13 PM
Problem using uri->segment - should be easy....[SOLVED] - by El Forum - 12-15-2007, 04:22 PM
Problem using uri->segment - should be easy....[SOLVED] - by El Forum - 12-15-2007, 04:24 PM
Problem using uri->segment - should be easy....[SOLVED] - by El Forum - 12-15-2007, 04:42 PM
Problem using uri->segment - should be easy....[SOLVED] - by El Forum - 12-15-2007, 05:23 PM



Theme © iAndrew 2016 - Forum software by © MyBB