Welcome Guest, Not a member yet? Register   Sign In
APP_NAMESPACE do nothing..
#4

CodeIgniter provides two methodologies you can use - the traditional, non-namespaced, controllers that are found by the folder, and now having namespace usage built-in. The Home controller is not namespaced to make it a little more familiar to those coming from previous versions of CodeIgniter. With namespaces, remember you have to declare them at the top of the file. So, if you want Home controller to be namespaced and available under the App\Controllers namespace you'll need to declare that:

Code:
<?php namespace App\Controllers;

class Home extends \CodeIgniter\Controller
{
    . . .
}

The APP_NAMESPACE constant is used to allow the application folder's namespace to be changed easily. However, that still means you have to declare the correct namespace within each class in the application folder. This is used within application/Config/Autoload.php to define the application folder as whatever namespace you've set it be. Which means controllers are namespaced to App\Controllers, models to App\Models, etc.

One caveat if you change the app's namespace - you might need to update the defaultNamespace setting in the routes file to match. The autoloader will first attempt to find a class matching the default namespace and the class name mentioned in the router, so App\Controllers\Home in this case. If it can't find that one, it looks for \Home (with no namespace).
Reply


Messages In This Thread
APP_NAMESPACE do nothing.. - by sv3tli0 - 06-28-2016, 12:54 AM
RE: APP_NAMESPACE do nothing.. - by titounnes - 06-28-2016, 02:58 AM
RE: APP_NAMESPACE do nothing.. - by idealcastle - 06-28-2016, 04:54 AM
RE: APP_NAMESPACE do nothing.. - by kilishan - 06-28-2016, 06:23 AM
RE: APP_NAMESPACE do nothing.. - by kilishan - 06-28-2016, 06:24 AM
RE: APP_NAMESPACE do nothing.. - by titounnes - 06-28-2016, 07:35 AM
RE: APP_NAMESPACE do nothing.. - by sv3tli0 - 06-28-2016, 11:00 AM
RE: APP_NAMESPACE do nothing.. - by kilishan - 06-28-2016, 11:28 AM
RE: APP_NAMESPACE do nothing.. - by kilishan - 06-28-2016, 09:03 PM
RE: APP_NAMESPACE do nothing.. - by TenaciousC - 06-29-2016, 05:12 AM
RE: APP_NAMESPACE do nothing.. - by titounnes - 07-01-2016, 12:00 PM
RE: APP_NAMESPACE do nothing.. - by arma7x - 07-01-2016, 03:00 PM



Theme © iAndrew 2016 - Forum software by © MyBB