New to CI - stuck on news tutorial with an 'Undefined property' error |
[eluser]jimbojames[/eluser]
Hi All, I am new to CI coming from a .Net background. I have been following the tutorial and all was going well until I got to the end of the news tutorial section. I am getting the following error when I try and visit my index.php/news page: Code: A PHP Error was encountered I have checked my code line by line and can't see any differences between the tutorial and my versions. I have set up logging in MySQL and I can see that CI is hitting the DB and registering the following entry in to the logs: Code: Init DB root I have also checked to see if all my cases are correct, which they seem to be. I have now been trying to fix this error for 8 hours and I'm out of ideas. Any help would be greatly received! FYI (if it helps diagnose the issue), I am running a Mac on Mountain Lion 10.8.3 with the latest CI, MySQL and PHP installations. Thanks in advance, James
[eluser]jimbojames[/eluser]
Anyone? Really thought I would have a reply by now!
[eluser]TheFuzzy0ne[/eluser]
Patience is a virtue. Don't forget, the people who help others on these forums are volunteers -- we don't get paid for it. Sometimes it can take a while to get a reply. I've just finished replying to some posts that have been waiting over a week. Generally, replies are quite fast (usually within a few hours), but often people are busy with real-life responsibilities and posts can be overlooked. Anyway... Welcome to the CodeIgniter forums! First of all, it would help a lot if you posted your controller. It sounds to me as if you are not loading your model.
[eluser]jimbojames[/eluser]
Hi TheFuzzyOne, I'm sorry, maybe I was a bit hasty, but I was looking forward to learning a new framework and to then get an error on the tutorial, spend hours trying to resolve it with Google, finally throw the towel in and post in these forums and then no reply (at first), I was a bit disappointed. Anyway, my controller code is the same at the tutorial from the CI site: Code: <?php Can you see any errors? I have since read that it looks as if Ellis Lab is going cold on CI and there is only 1 guy contributing at the moment. What's your thoughts?
[eluser]TheFuzzy0ne[/eluser]
Sorry, which tutorial is it that you're following? The one in the user guide? The reason I ask is that what you've posted looks nothing like what in the user guide tutorial. However, I also see no reason why it shouldn't be working. Have you modified any system files? I don't think Ellislab is going cold on CI, but it certainly seems that it's not a priority for them anymore (perhaps this is because it's not profitable enough?), and that they don't want it to get too far ahead of itself. As it stands, CodeIgniter is a great framework, and it has some of the best documentation I've ever seen. However, CodeIgniter seems to be lacking direction and leadership. I'm hoping that CodeIgniter will eventually pick up the slack again, but I guess we'll just have to wait and see. In order for CodeIgniter to utilise some of the new PHP features, it would involve a complete rewrite, which I don't think Rick wants. With that said, CodeIgniter is still very much alive, and community-driven, and there's definitely more than one contributor. https://github.com/EllisLab/CodeIgniter/
[eluser]phpLearner[/eluser]
change $data['news'] to $data['news_item'] in function view($slug){ }
[eluser]TheFuzzy0ne[/eluser]
Please make sure error reporting is enabled. At the beginning of index.php: Code: <?php if ( ! defined('BASEPATH')) exit('No direct script access allowed'); Also, double-check that you don't have any errors displaying before the one you posted. Sometimes one error snowballs and causes more errors, and fixing the first one fixes subsequent errors. Please also post the contents of ./application/models/news_model.php
[eluser]jimbojames[/eluser]
I added the code as you said but all I get displayed, no matter what url I visit in the app is 'no direct script allowed' I looked at the index.php file and it has this section already in it: Code: define('ENVIRONMENT', 'development'); So am I right to think it's already in the right reporting mode? The extra code you required is: Code: <?php Thanks for your help with this, much appreciated!
[eluser]TheFuzzy0ne[/eluser]
By default, error reporting should be enabled in your php.ini, but I find that sometimes it's not, so I like to explicitly call ini_set('display_errors', '1') just to be sure. I'm not sure if/how it'll fix your problem, but you're not calling the parent constructor from your model: Code: class News_model extends CI_Model { |
Welcome Guest, Not a member yet? Register Sign In |