Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Exception or disable toolbar for specific URI #195

Closed
sayonara90s opened this issue Jul 28, 2016 · 9 comments
Closed

Exception or disable toolbar for specific URI #195

sayonara90s opened this issue Jul 28, 2016 · 9 comments

Comments

@sayonara90s
Copy link
Contributor

I have tried 'filter' and used 'except' key for URI, but not working.

    public $globals = [
        'before' => [
            //'csrf'
            'auth'
        ],
        'after'  => [
            'toolbar' => ['except' => 'source/*']
        ]
    ];

And I gotten an error:

ErrorException

    array_key_exists(): The first argument should be either a string or an integer

BASEPATH/Filters\Filters.php at line 69

Is there any suggestion?

I think that is only for development mode.

@lonnieezell
Copy link
Member

I won't have a chance to really look at it until later tonight, but I believe you need the value of 'except' to be an array:

'after'  => [
    'toolbar' => ['except' => ['source/*']]
]

I should probably have that attempt to do an auto-conversion to array if a string is found, though, since I can see that being a common error point.

@sayonara90s
Copy link
Contributor Author

'after'  => [
    'toolbar' => ['except' => ['source/*']]
]

Still getting an error.

Example in this case:

I have a controller to send output as JavaScript's content (to minify it on the fly).

class Source extends Controller {

    public function js($encFile = '')
    {
        $output = @file_get_contents(WRITEPATH ."scripts/{$encFile}.js");
        // ...
        $response->send();
    }

}

The problem is when debug bar activate, the output included debug bar.

//ci4play.dev/source/js/whateverscript.js
    function myscript(){//....}

    // debug bar output HTML
    // .....

I think the exception of toolbar is very useful to avoid collisions with other template.

@lonnieezell
Copy link
Member

Should be working now, but let me know if you still run into problems.

@sayonara90s
Copy link
Contributor Author

Haha.. Its working now! Thank you. :)

@sayonara90s
Copy link
Contributor Author

sayonara90s commented Aug 6, 2016

Ooops!

public $globals = [
    'after'  => [
        'toolbar' => ['except' => ['test/*']]
    ]
];

The toolbar is still shown when I accessed the only controller of URI (without method, second of URI segment), like this:

ci4play.dev/test

It's ok (toolbar is hidden):

ci4play.dev/test/index

What do you think?

Thanks. :)

@Fabio-Zeus-Soft
Copy link

Is it possible that this issue is back?
My code:

'after' => [
            'pagecache',        // Web Page Caching
            'performance',      // Performance Metrics
            'toolbar' => [      // Debug Toolbar
                'except' => ['challenge']
            ]
        ],

Still getting: TypeError: array_key_exists(): Argument #1 ($key) must be a valid array offset type

@kenjis
Copy link
Member

kenjis commented Jun 11, 2024

Use $global filter, instead of $required.
See https://codeigniter4.github.io/CodeIgniter4/incoming/filters.html#globals

@EmbDclic
Copy link

It seems very counterintuitive to move 'toolbar' from the new $required to $globals. I think it would be good to specify this in the documentation if 'except' is not supported for the required filters.

@kenjis
Copy link
Member

kenjis commented Jun 21, 2024

Read https://codeigniter4.github.io/CodeIgniter4/incoming/filters.html#required
There is no except.

See the PHPDoc @var. It is clear that you cannot set an array like 'toolbar' => ['except' => ['challenge']]

* @var array{before: list<string>, after: list<string>}
*/
public array $required = [
'before' => [
'forcehttps', // Force Global Secure Requests
'pagecache', // Web Page Caching
],
'after' => [
'pagecache', // Web Page Caching
'performance', // Performance Metrics
'toolbar', // Debug Toolbar
],
];

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants