2

I am building an app in codeigniter and my application folder hierarchy goes like this:

|-controller
   |-admin
      |-dashboard

I want to add dashboard to the namespace admin, so I did this:

defined('BASEPATH') OR exit('No direct script access allowed');
namespace admin;
class Dashboard extends MY_Controller {
     //constructor and some methods
}

The problem is that whenever i try to access the dashboard class from uri localhost/myapp/admin/dashboard, I get error on the browser like this:

Server error

500

However if I comment out the line namespace admin; , it runs without any errors.

Why is the namespace creating such internal server error?

How to prevent such error while using namespaces for controller class in codeigniter?

5
  • First check which version of PHP and codeigniter you are using and let us know . CodeIgniter does not support namespaces depending on version. If you want to use namespaces php version must be >= 5.3.0 Codeigniter doesn't use namespaces because it is written to support php 4 Commented Feb 19, 2016 at 16:41
  • let me know if that helps you Commented Feb 19, 2016 at 16:43
  • php 5.6 and CI version 3.0.1 Commented Feb 19, 2016 at 16:45
  • 1
    Actually there is problem of namespaces with Codeigniter as codeigniter was built in PHP4 and Namespace came in PHP5 Commented Feb 19, 2016 at 16:49
  • I have added this as answer please accept it as answer if it helps you Commented Feb 19, 2016 at 16:51

2 Answers 2

1

The reason for this is Codeigniter does not natively support namespaces. They did this to allow backwards compatibility of Codeigniter for PHP 4. Namespaces only became available in PHP 5.3.0 and later versions.

Sign up to request clarification or add additional context in comments.

Comments

1

First check which version of PHP and codeigniter you are using and let us know .

CodeIgniter does not support namespaces depending on version. If you want to use namespaces php version must be >= 5.3.0 Codeigniter doesn't use namespaces because it is written to support php 4

If you must have to use namespaces then I am linking you to Stack Overflow Similar Problem link that has Upvoted reference for using Namespace with Codeigniter By making configuration editing. You can try that but by default it does not support it

1 Comment

For more reference You can see things added to CodeIgniter 3 in link given below reddit.com/r/PHP/comments/30u0w9/codeigniter_3_is_out

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.