controller redirect to method fails |
Greetings, So far I like the concepts and implementation of CI4 - great job!
However, I can't get the CI3 redirect equivalents to work in CI4. I'm using the CI4 Beta 4.0.0 - 1, composer installed. Desired function: Controller needs to pass control to another controller (or method, module, service, etc). Purpose: I created a login module because I have 4 applications using similar code. I will use routes to return control, and encrypted cookies for validations. BUT, perhaps there may be a bug somewhere. The code below seems too simple to fail. Minimalist failing code: - I added the route: $routes->get('/(:any)', 'Home::$1'); - Modified the canned Home controller to add a dummy method - Directly calling http://localhost/dummy works just fine. - redirect ('dummy'); fails, as do all derivative approaches like: route_to('dummy'), header ("location: dummy"); specifying namespaces and home controller ("app\home\dummy"), etc. all fail... Code follows. Help anyone?? config/routes: $routes->get('/(:any)', 'Home::$1'); (and also tried ...->add and other hacks to no avail) <?php namespace App\Controllers; use CodeIgniter\Controller; class Home extends Controller { public function index() { redirect ("dummy"); echo "didn't route."; //return view('welcome_message'); } public function dummy() { echo "Dummy route."; } } - Thanks
(03-12-2019, 10:41 AM)donpwinston Wrote: Try redirect('/dummy'); Thanks, I did that and all variations of locations and namespaces, etc. It seems the correct answer is: return redirect()->to('ci4/dummy'); // ('ci4' is my new "public" directory where index.php resides) I found the answer in another post: https://forum.codeigniter.com/thread-72681.html Note that ":redirect ('ci4/dummy');" will also fail. The reason I mentioned it as a bug is because the fail is: SYSTEMPATH/HTTP\Exceptions\HTTPException.php at line 106 Thanks all!
can you try $this->response->redirect( 'dummy' ); ?
had also some problems with the redirect helper, but the response function works great for me:
You have to return any redirects. Simply calling redirect doesn't work.
Code: public function index() {
Following up: Full code examples below of what worked and didn't...
Thanks for all the suggestions. Most failures end with a CI4 code exception: SYSTEMPATH/HTTP\Exceptions\HTTPException.php at line 106 The root problem for me is simply vague documentation about reverse routing. I've just no desire to poor through the CI4 system code. I should mention I'm writing modules in different directories and namespaces with a "global" config, so I needed a general solution to redirect routing, etc... PHP Code: <?php namespace App\Controllers; |
Welcome Guest, Not a member yet? Register Sign In |