ingeniasoftware / luthier-ci

Improved routing, middleware support, authentication tools and more for CodeIgniter 3 framework
https://luthier.ingenia.me/ci/en/
MIT License
150 stars 38 forks source link

Stop controller's funcions on using the middleware #8

Closed mateusmcordeiro closed 6 years ago

mateusmcordeiro commented 6 years ago

Hi First of all, I wanna thank you for my last issue. Now, im facing a problem with my controllers functions, in other words, I'm using the middleware, but my controller is still using its functions. This is a problem, because I need the middleware stop that exec.

andersonsalas commented 6 years ago

Hi,

That's the normal behaviour of Luthier-CI; the controller will run after the middleware unless you stop the script execution explicitly. You can use the die() or exit() function inside your middleware to archieve that (return statement will not work)

<?php

defined('BASEPATH') OR exit('No direct script access allowed');

class Test_middleware
{

    /**
     * Middleware entry point
     *
     * @return void
     */
    public function run()
    {
        /* YOUR CODE */
        exit; 
    }
}

Refer to Middleware execution points topic for more information.

Cheers.