Welcome Guest, Not a member yet? Register   Sign In
News article pages 404
#21

[eluser]cjobes[/eluser]
Looking back at the tutorial, I found some problems that may be causing the confusion, but I'm still a bit confused in the end.

Here are a few things I have found:
In the News section of the tutorial you are given the code to create a table in the database you created for the tutorial. You are also asked to create a few "seed" records. In my table I created three records like this:
Record 1
Title: New TitleOne
Slug: News SlugOne
Text: News One Txt

Record 2
Title: New TitleTwo
Slug: News SlugTwo
Text: News Two Txt

Record 3
Title: New TitleThree
Slug: News SlugThree
Text: News Three Txt

Later, on the same, page you are given the code to write the News controller. The code for the view looks like this:
Code:
$data['news'] = $this->news_model->get_news($slug);

Further down the page you are told to add to the view method. Here you need to be careful and actually RE-WRITE the method, rather than add to it. That is what I did, which left the first line using the $data key of 'news', while the new set of code changed it and used 'news_item' as the key instead. The instructions say to add the code, so I naturally thought I needed to add the new code to what I wrote before. Right off the bat there is an error that is so minute to find.

However, after fixing that minor detail, it still did not fix my problem. I kept noticing that my URL, when trying to view a single news item, was not looking right.

The routing code that takes care of this is
Code:
$route['news/(:any)'] = 'news/view/$1';
So the value of the "slug' field in the database is what is being passed to the view method. My address bar was showing the following:
Code:
/index.php/news/News SlugTwo
You can't see it in the code above because this site is removing it, but after "/News" there is a space, and the address bar replaces that space with % 20, and this is what gets passed to the view method. That gets sent to the model, but it can't find such a record, because my record does not have a % 20 as part of the slug value.

To test this I created another entry using a one word string, no spaces. Everything then worked fine. I then took the slug value of the records I first created in the table and removed the space from them. Again, it worked fine.

So the problem is in the way the segment is being interpreted. The confusion is now about how to get around this, which is not covered at all in the tutorial.

C
#22

[eluser]stuartr[/eluser]
With reference to the issue with spaces in the slug name, I also hit this when creating the initial articles as the tutorial wasn't clear that the slug would be used to create the URL and hence would be sensitive to certain characters such as a space or an apostrophe.

That being said, when you reach the section on creating the news article the set_news function created in the model takes care of this with the assistance of the URL helper.

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


The problem I am trying to get my head around at the moment is the link to the news article, assuming I end the URL without a trailing slash the link is built as ci_test/index.php/news/slug1, whereas if I call the page with a trailing slash I get ci_test/index.php/news/news/slug1.

e.g.
http://ci_test/index.php/news (no trailing slash) builds links as http://ci_test/index.php/news/slug1
while
http://ci_test/index.php/news/ builds links as http://ci_test/index.php/news/news/slug1

While I entirely understand the logic of what is happening with the relative URL, I am new to working with segmented URLs and CI, and am therefore still trying to get my head around the best approach to managing this. I can get it to work with an additional route
Code:
$route['news/news/(:any)'] = 'news/view/$1';
but that seems messy so it seems as if I am still missing something at the moment.
#23

[eluser]stuartr[/eluser]
Found in another post
[quote author="Aken" date="1345941381"]This has been brought up SO many times now.

The URL the tutorial tells you to create is a relative URL. Relative URLs suck. It should recommending using an absolute URL, or even better, the site_url() or anchor() functions from the URL helper.[/quote]

Not going to disagree with the view of relative URLs, so will stick with absolute URLs created with the URL helper as suggested.

If as Aken says this has been brought up so many times before, It would make sense to amend the tutorial. Tutorials are a key marketing tools, with so many frameworks available they are one of the key ways that people will try to assess which framework they will adopt. Leaving potential users having to spend hours trawling forums before they have even completed a tutorial will inevitably turn some potential users off.

I worked through the tutorial a few weeks back - hit the problem and moved onto other things - learning a new framework will have to compete with many other calls on my time, and by making it messier than it needs to be decreases the chance that I will choose to invest the time in framework A rather than B, C, D or any of the others vying for my attention.

As it happens I have picked it back up again following a chance conversation with someone, but that's just luck.
#24

[eluser]cjobes[/eluser]
Yes, tutorials are the best way to get people to understand the framework, and I really like the way they have done it with CI. Which is another reason I reacted to this thread the way I did.

When you go so far, and things look so promising, then to come to a problem like that, the next step is to check the community for answers. Getting an answer to help you get on your way is key. Especially when you are trying to determine if the framework is and answer for something you need as part of your job.

If I have an answer I am not going to dangle a carrot in front of someone. They are probably just as frustrated as I was when learning something. It's even more frustrating to know that someone has an answer, but they won't give it. After a while you just move on and find something else. What else are these forums are for, if not to answer questions and to help and encouraging each other to excel?

Hopefully they will fix the tutorial. especially if this is a known issue.

C
#25

[eluser]Aken[/eluser]
[quote author="cjobes" date="1363376364"]What else are these forums are for, if not to answer questions and to help and encouraging each other to excel?[/quote]

Guiding you in the right direction towards solving the problem on your own will teach you much more than handing you the answer. Which, I pretty much did anyway by stating that the 404 error was being generated by the function. Learning to debug and problem solve is an essential skill for a programmer.

The tutorial can be updated by anyone with a Github account who knows how to make a pull request. If you'd like to help make CI better, you're welcomed to contribute.
#26

[eluser]stuartr[/eluser]
[quote author="Aken" date="1363413421"]Guiding you in the right direction towards solving the problem on your own will teach you much more than handing you the answer. Which, I pretty much did anyway by stating that the 404 error was being generated by the function. Learning to debug and problem solve is an essential skill for a programmer.[/quote]

Most of the time I would agree with you, however with regards to errors in the tutorial, its more useful for these to be pointed out explicitly. As the stage of approaching a tutorial, particularly if trying to adopt a new mindset (e.g. moving to a framework approach), its not clear where my normal practices should apply, and where the framework has over-ridden these as part of the change in approach. This is why many of us, when adopting something like a framework will often miss things in a tutorial, that we would have picked up in the way we currently work.

As mentioned a tutorial is a key marketing tool for a framework such as CI, and there should be more focus on making it easy to follow and getting it right, as its usually after this that I will make a decision to adopt a particular framework and will be willing to spend time figuring it out in more detail.

That said, I believe that tutorials are the exception to the normal rule, and outside of the tutorial IMO you are completely right - guidance is what we need, to help develop our own problem solving skills and deeper understanding, rather than spoon-fed answers

[quote author="Aken" date="1363413421"]The tutorial can be updated by anyone with a Github account who knows how to make a pull request. If you'd like to help make CI better, you're welcomed to contribute.[/quote]

Probably not wise for CI noobs like myself to be updating a tutorial that we are having difficulties in following - I have seen too many instances of documentation being made worse by well-intentioned people who didn't really understand what they were trying to update.

The problem with tutorials is that the people with the understanding to make updates often don't see the errors due to their implicit understanding of "what is really meant" by an instruction, and the people who need the tutorial most will be caught out by the ambiguity.

Oh well, onwards and upwards, as I continue my adventures with CI :-)




Theme © iAndrew 2016 - Forum software by © MyBB