Create news items Tutorial Not Working |
Hi guys
I'm a newbie in codeigniter and has been following the tutorial until I hit death end in the last tutorial 'Create New Item'. I tried to insert data into MySQL: http://localhost/codeIgniter/index.php/news/create and hit error: The webpage cannot be found HTTP 404 I tried to update my config.php from Code: $config['base_url'] = 'http://localhost/codeIgniter/'; Code: $config['base_url'] = ''; My routes.php: Code: $route['news/create'] = 'news/create'; My controller News.php Code: <?php My model News_model.php Code: <?php My view create.php Code: <h2><?php echo $title; ?></h2> Thanks in advance!
Try comment the routes.php line:
PHP Code: //$route['news/(:any)'] = 'news/view/$1'; And see if it works. This route is overriding the "$route['news/create'] = 'news/create';" and going the the show_404() inside the view method. If to comments solves, try put the news/create route below of the news/(:any). Remove the comment and test.
Don't leave $config['base_url'] empty.
For more information: https://www.codeigniter.com/user_guide/i...index.html Routes like: PHP Code: $route['news/create'] = 'news/create'; are useless. You're telling CodeIgniter to behave in a way it already knows. If the http request is news/create, then by default CI will look for a method (= function) named "create" inside the controller "News.php". You don't need a route for that. The route PHP Code: $route['news/(:any)'] = 'news/view/$1'; is useful, because it tells CI to look for the method "view" inside the controller "News", and pass everything after the news/ part as a parameter for that method.
(01-29-2018, 02:06 PM)Wouter60 Wrote: Don't leave $config['base_url'] empty. Once I remark this, I hit error: 404 Page Not Found
All routes that (:any) in them need to be the last routes in the routes file,
or they will over ride all the other routes. What did you Try? What did you Get? What did you Expect?
Joined CodeIgniter Community 2009. ( Skype: insitfx )
(01-30-2018, 05:07 AM)InsiteFX Wrote: All routes that (:any) in them need to be the last routes in the routes file, Tried the below but no luck Code: $route['news/create'] = 'news/create';
The 404 is being generated because the News Tutorial is missing
the view/news/success.php HTML view... In the News/create method view/news/success.php PHP Code: <?php I just built the whole tutorial and it runs fine! There is an error in the News controllers constructor: PHP Code: /** What did you Try? What did you Get? What did you Expect?
Joined CodeIgniter Community 2009. ( Skype: insitfx )
(02-01-2018, 01:01 PM)InsiteFX Wrote: The 404 is being generated because the News Tutorial is missing Thanks for the reply. However, the result is still the same I attach my codes here ...
02-02-2018, 05:00 AM
(This post was last modified: 02-02-2018, 05:14 AM by InsiteFX. Edit Reason: Added Attached file )
You must have a setup configuration problem because it runs fine here.
For some reason it will not let me attach the zip file. You can download my version from here. News Tutorial Download Like I said this is tested and working here so if it doe's not work for you then you have a setup of apache php etc; Problem. What did you Try? What did you Get? What did you Expect?
Joined CodeIgniter Community 2009. ( Skype: insitfx )
(02-02-2018, 05:00 AM)InsiteFX Wrote: You must have a setup configuration problem because it runs fine here. Thanks. I tried yours but same result. I will reinstall apache/php/mysql and update the result here. |
Welcome Guest, Not a member yet? Register Sign In |