Trying to show a single blog post - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20) +--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23) +--- Thread: Trying to show a single blog post (/showthread.php?tid=30607) |
Trying to show a single blog post - El Forum - 05-20-2010 [eluser]kaos78414[/eluser] So for practice I'm trying to create a blog with commenting functions and AJAX and all the normal stuff. The problem I ran into, is I can't seem to pull a single entry for viewing. I have the entries truncated on the first page with a read more link, to bring them into full view. This is the code for in the controller for viewing a blog entry: Code: function view() { And this is in the model: Code: function get_view(){ And the view has: Code: <div id="post"> I've done some tutorials, but I just can't seem to see what I'm doing wrong here. Can anyone enlighten me? Trying to show a single blog post - El Forum - 05-20-2010 [eluser]kaos78414[/eluser] Btw, the error I get says that the problem is in the view: A PHP Error was encountered Severity: Notice Message: Trying to get property of non-object Filename: views/postview.php Line Number: 3 And also line number 6, same error. Any help is appreciated Trying to show a single blog post - El Forum - 05-20-2010 [eluser]kaos78414[/eluser] I found part of the problem, the URI segment isn't getting passed correctly for some reason. If I change $this->uri->segment(3) to $this->uri->segment(3, 1), it passes 1 and the blog with the id 1 shows up correctly. So the uri segment is passing FALSE to the view, which is a non-object. I'm not sure why this is happening. Trying to show a single blog post - El Forum - 05-20-2010 [eluser]kaos78414[/eluser] Further investigation: It's not my .htaccess file. There are no syntax errors. The url segment simply isn't getting passed to the model. I can't figure out why. Does anyone have any idea why this is happening? I've autoloaded the correct libraries and helpers. I don't see what could be causing this issue. EDIT: Changing the code around, i moved the segment call to the function in the controller, passing it as a variable to the function in the view. This produces the same result. Any ideas? Trying to show a single blog post - El Forum - 05-20-2010 [eluser]Mr. Pickle[/eluser] Try approaching it as an array. The error states the $post var is not an object. Trying to show a single blog post - El Forum - 05-20-2010 [eluser]Mr. Pickle[/eluser] You can also put Code: print_r($post); If it says false, you now there is nowt data in it. Trying to show a single blog post - El Forum - 05-20-2010 [eluser]kaos78414[/eluser] How exactly do I do that? The $post var should be returning $this->uri->segment(3). How do I list that as an array? print_r($post); shows nothing at all. Trying to show a single blog post - El Forum - 05-20-2010 [eluser]danmontgomery[/eluser] Make sure you're not loading the url library twice... If you load it more than once, the url information is lost. Trying to show a single blog post - El Forum - 05-20-2010 [eluser]kaos78414[/eluser] Nope everything looks fine. This is driving me crazy haha Trying to show a single blog post - El Forum - 05-20-2010 [eluser]cahva[/eluser] How about if you change your code like this: Controller: Code: function view($blog_id = FALSE) { and the model: Code: function get_view($blog_id){ As you see I removed using of $this->uri->segment(3). You can get the blogid just by adding it as a parameter to view method. |