Welcome Guest, Not a member yet? Register   Sign In
CodeIgniter Tutorial News section
#15

(07-31-2015, 11:09 AM)Wouter60 Wrote: Check if your controller has multiple index() and view() functions in it. Your example code that you posted earlier this week shows that it does. Function names inside a class must be unique. When the documentation says that you have to add code to the index function in your controller, don't create a new function, but put the extra code before the closing curly brace of the existing index function. The same goes for the view() function.

Besides all that,  you are not supposed to get an http 500 error, but a readable php error message on your localhost. Check your index.php file for the setting of the ENVIRONMENT constant. Does it say 'development' or 'production'?
Development suppresses php error messages. That's fine when your website is online, but while you are writing, testing and debugging your application, you want to see what's going wrong, don't you?

The http 500 error may also be caused by (a) bad server configuration or (b) an error in your .httaccess file.
To check (a): type http://localhost in your browser. You should get the welcome page of your server.
To check (b): rename your .htaccess file to .htaccess_org and try to start your website again. It should start the index.php file with your default controller.

If you are still getting the same error, please upload your News.php file as an attachment to this topic.

(1) Yes there were multiple index() and view() functions in News.php, so I've fixed that and now this is my current News.php file.

Code:
<?php
class News extends CI_Controller
{
       public function __construct()
       {
               parent::__construct();
               $this->load->model('news_model');
       }

       public function index()
       {
       $data['news'] = $this->news_model->get_news();
       $data['title'] = 'News archive';

       $this->load->view('templates/header', $data);
       $this->load->view('news/index', $data);
       $this->load->view('templates/footer');
       }

       public function view($slug = NULL)
       {
       $data['news_item'] = $this->news_model->get_news($slug);

               if (empty($data['news_item']))
               {
               show_404();
               }

       $data['title'] = $data['news_item']['title'];

       $this->load->view('templates/header', $data);
       $this->load->view('news/view', $data);
       $this->load->view('templates/footer');
       }
}

After changing that I now get this error message

An Error Was Encountered
Unable to load the requested class: Authentication

(2) I've checked C:/xampp/htdocs/MyProject/index.php and changed this line
define('ENVIRONMENT', isset($_SERVER['CI_ENV']) ? $_SERVER['CI_ENV'] : 'development');
to
define('ENVIRONMENT', isset($_SERVER['CI_ENV']) ? $_SERVER['CI_ENV'] : 'production');
but the results are no different however above that line it says
NOTE: If you change these, also change the error_reporting() code below
but there are 3 error_reporting() codes and I don't know which to change
error_reporting(-1);
error_reporting(E_ALL & ~E_NOTICE & ~E_DEPRECATED & ~E_STRICT & ~E_USER_NOTICE & ~E_USER_DEPRECATED);
error_reporting(E_ALL & ~E_NOTICE & ~E_STRICT & ~E_USER_NOTICE);

(3a) When I point my browser to http://localhost I get the XAMPP Welcome message and the URL changes to http://localhost/xampp/ but you say I should get "welcome page of your server" so I guess that means Apache server.

(3b) I've renamed 2 htaccess files to htaccess_org
C:/xampp/htdocs/MyProject/htaccess_org
C:/xampp/htdocs/MyProject/application/htaccess_org

Having done all of that I still get the error message

An Error Was Encountered
Unable to load the requested class: Authentication

I've searched many files but can't find a class named "Authentication".
Reply


Messages In This Thread
RE: CodeIgniter Tutorial News section - by christaliise - 08-01-2015, 08:13 AM



Theme © iAndrew 2016 - Forum software by © MyBB