Welcome Guest, Not a member yet? Register   Sign In
IDEA: Controller Extended by Default
#6

I do like that this puts it in the same directory and namespace as the controllers that will extend it. I think it will still need a route though, because otherwise visiting example.com/base will give cause "Controller method is not found: index" since the controller itself is valid.
If everyone is feeling good about this I will open a pull request as the next part of the conversation. Here is my updated skeleton proposal given this new location:

PHP Code:
<?php namespace App\Controllers;

use 
CodeIgniter\Controller;

class 
Base extends Controller
{
    protected 
$helpers = [ ];
    
    public function 
__construct()
    {

    }


And I'd recommend adding this to system/Config/Routes.php:
PHP Code:
// Prevent access to Base controller
$routes->add('base/(:any)', function()
{
    throw \
CodeIgniter\Exceptions\PageNotFoundException::forPageNotFound();
}); 


*Note: forPageNotFound() currently incorrectly requires a parameter. I have a pull request to fix this: https://github.com/codeigniter4/CodeIgniter4/pull/1842
Reply


Messages In This Thread
IDEA: Controller Extended by Default - by MGatner - 03-18-2019, 07:28 AM
RE: IDEA: Controller Extended by Default - by MGatner - 03-19-2019, 07:25 AM



Theme © iAndrew 2016 - Forum software by © MyBB