Welcome Guest, Not a member yet? Register   Sign In
Controller or its method is not found: \\App\\Controllers\\Home::index
#21

(This post was last modified: 03-07-2022, 10:28 PM by kenjis.)

To show Before Filters | After Filters, you need to update to the develop branch.
If you use appstarter, it is easy.
https://codeigniter4.github.io/CodeIgnit...latest-dev

If Apache redirects, you have apache configuration for it.
Check the apache config file or .htaccess.

If Controller filters redirect, you have config for the filter, and the filter itself.
Check app/Config/Filters.php, app/Config/Routes.php
Reply
#22

if I disable $routes->setAutoRoute(false); and define a route like

$routes->get('/Testing', 'Testing::testmethod');

I get 404 Can't find a route for 'Testing/testmethod'.

In regards to 303, I found the below definition 303 error


A 303 See Other message is an HTTP response status code indicating that the requested resource can be found at another URI (address) by using the GET HTTP method. The 303 See Other code is typically provided in response to a POST, PUT, or DELETE HTTP method request, which indicates to the client that the server successfully received the data associated with the request, and the client should send a new GET request to the new URI it was provided by the server.

in codeigntier I am not sure if redirect() is receiving a post to redirect to a get is it?
Reply
#23

(This post was last modified: 03-08-2022, 12:44 AM by kenjis.)

In CI4 all controllers have its own namespaces.
Specify full namespaces (starting with \) like '\App\Controllers\Api\v1\User_controller::index',
or relative namespaces to the default namespace for routing ('\App\Controllers' by default) in the Routes.php.

> in codeigntier I am not sure if redirect() is receiving a post to redirect to a get is it?

Sorry, I don't get what you ask.
Your problem is what is redirecting (Apache or CodeIgniter), and to remove the config/code to redirect is the solution.

When you enable csrf filter, you get 303 if you don't send correct token with the POST request.

Postman automatically follows redirects by default.
See "Settings".
Reply
#24

Hi Kenjis,

I certainly learnt a lot today - thank you! I will have to upgrade to the development version as cannot see anything in my filters that would redirect.

When you enable csrf filter, you get 303 if you don't send correct token with the POST request.
>> But that equals a redirect?

Postman automatically follows redirects by default.
>> Ok, let me test. Thank you for that info.

Sorry to go back routes but I have the following route;
$routes->get('/Testing', '\AppXXX\Controllers\Testing::testmethod');
With $routes->setAutoRoute(false); the route doesnt work but with it set to true, it works. Sorry, how is that possible?
Reply
#25

(This post was last modified: 03-08-2022, 01:19 AM by kenjis.)

(03-08-2022, 12:52 AM)spreaderman Wrote: When you enable csrf filter, you get 303 if you don't send correct token with the POST request.
>> But that equals a redirect?

If CSRF token is not sent or correct, CI4 redirects by default if not Ajax request.
See https://codeigniter4.github.io/CodeIgnit...on-failure

(03-08-2022, 12:52 AM)spreaderman Wrote: $routes->get('/Testing', '\AppXXX\Controllers\Testing::testmethod');
With $routes->setAutoRoute(false); the route doesnt work but with it set to true, it works.  Sorry, how is that possible?

> With $routes->setAutoRoute(false); the route doesnt work.
It means the route definition is something wrong.

> $routes->get('/Testing', '\AppXXX\Controllers\Testing::testmethod');
It means
When you navigate to https://your.site.example.com/Testing, \AppXXX\Controllers\Testing controller's
testmethod() is executed.

> but with it set to true, it works.

It means you have \App\Controllers\Testing controller, because
auto routing can only execute controllers in app/Controllers/ directory.

Anyway, you can check all routes by spark routes command.
Reply
#26

(This post was last modified: 03-08-2022, 08:56 PM by spreaderman.)

Hi Kenjis,

I am beginning to think this it is not a filter. Again, the redirect only happens on POST while GET works. I have review my filters and .htaccess and cannot see anything wrong.

I see one other person have a similar problem here here:

In above post, it was suggested to "... check your csrf filter and add an exception for your post requests".

First step is I tried to echo session()->getFlashdata('error'); but empty.

Secondly, I then changed Security.php to public $redirect = false; but it still produces 303 and then reverts to get /

Sorry, I completely forgot to look at config/Filters.php and found this! Exactly as you said. Now I have to find a way to make an exception safely.

public $globals = [
'before' => [
// 'honeypot',
'csrf',
],
'after' => [
'toolbar',
// 'honeypot',
],
];
Reply
#27

(This post was last modified: 03-08-2022, 08:59 PM by kenjis.)

(03-08-2022, 08:42 PM)spreaderman Wrote: First step is I tried to echo session()->getFlashdata('error'); but empty.

Secondly, I then changed Security.php to public $redirect = false; but it still produces 303 and then reverts to get /

It seems CSRF filter has nothing to do with it.
But setting `$redirect = false` in the config file does not work because of a bug.

CSRF filter is this:
https://github.com/codeigniter4/CodeIgni...RF.php#L45
You can check by temporarily changing the code.
For example, adding `dd('csrf filter');'.

Okay, you have enabled csrf filter globally.
So all POST requests need valid CSRF token.
Reply
#28

So, it now is working as expected. I get "ok" from the controller. I will have to figure out how to add an exception for csfr for external post to api. Many thank yous Kenjis!
Reply
#29

Config Security `$redirect = false` does not work because of a bug.
It will be fixed in v4.2.0.
https://github.com/codeigniter4/CodeIgniter4/pull/5665
Reply




Theme © iAndrew 2016 - Forum software by © MyBB