Create news items Tutorial Not Working - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: Using CodeIgniter (https://forum.codeigniter.com/forumdisplay.php?fid=5) +--- Forum: General Help (https://forum.codeigniter.com/forumdisplay.php?fid=24) +--- Thread: Create news items Tutorial Not Working (/showthread.php?tid=69901) Pages:
1
2
|
Create news items Tutorial Not Working - aarontan78 - 01-29-2018 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! RE: Create news items Tutorial Not Working - natanfelles - 01-29-2018 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. RE: Create news items Tutorial Not Working - Wouter60 - 01-29-2018 Don't leave $config['base_url'] empty. For more information: https://www.codeigniter.com/user_guide/installation/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. RE: Create news items Tutorial Not Working - aarontan78 - 01-29-2018 (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 RE: Create news items Tutorial Not Working - InsiteFX - 01-30-2018 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. RE: Create news items Tutorial Not Working - aarontan78 - 01-31-2018 (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'; RE: Create news items Tutorial Not Working - InsiteFX - 02-01-2018 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: /** RE: Create news items Tutorial Not Working - aarontan78 - 02-01-2018 (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 ... RE: Create news items Tutorial Not Working - InsiteFX - 02-02-2018 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. RE: Create news items Tutorial Not Working - aarontan78 - 02-05-2018 (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. |