• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
redirect()

#1
I can't get redirect() to work. Is this yet to be worked on? I get a 'Unable to locate a valid route' error.

The route works form the browser's command box. 

Huh

Code:
<?php namespace App\Controllers;

use CodeIgniter\Controller;

class Register extends Controller
{
    private $session;
    private $validation;

    public function __construct(...$params) {
        parent::__construct(...$params);
        $this->validation =  \Config\Services::validation();
        $this->session = \Config\Services::session();
    }

    public function index()
    {
        print view('header.php', ['current' => 'register', 'title' => 'Register']);
        print view('register.php');
        print view('footer.php');
    }

    //--------------------------------------------------------------------

    public function step1()
    {
        $messages = [
           'name' => ['required' => 'The Name field is required'],
           'mailing-address-1' => ['required' => 'Street Address 1 is required'],
           'city' => ['required' => 'The City field is required'],
           'state' => ['required' => 'The State field is required'],
           'zip' => ['required' => 'The Zip field is required'],
        ];
        $this->validation->setRules([
            'name' => 'required',
            'mailing-address-1' => 'required',
            'city' => 'required',
            'state' => 'required',
            'zip' => 'required',
        ], $messages);

        if (! $this->validation->withRequest($this->request)->run())
       {
            print view('header.php', ['current' => 'register', 'title' => 'Step 1']);
            print view('step1.php', ['validation' => $this->validation]);
            print view('footer.php');
        }
        else
        {
            $this->session->set($this->request->getPost());
            redirect('/register/step2');
        }
    }

    public function step2()
    {
        print "<pre>" . print_r($this->session->get(), TRUE) . "</pre>";
    }
}
Simpler is always better
Reply

#2
Oops, someone else has the same problem. I guess it isn't fixed yet. Sorry.
Simpler is always better
Reply

#3
No one entered a bug report so it slipped my mind. Will work on it tonight, though. In the meantime - try it without the leading '/' and you should be fine.
Practical CodeIgniter 3  • CodeIgniter 4 Foundations - Coming Soon • Vulcan - CLI Tools for CI4
Reply

#4
Just added some more tests and everything seems to be working as expected. There was a fix directly related to what you're seeing that was added a couple of days ago. Please pull down the latest version of the CI4 and try again.
Practical CodeIgniter 3  • CodeIgniter 4 Foundations - Coming Soon • Vulcan - CLI Tools for CI4
Reply


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


Users browsing this thread:
1 Guest(s)


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2017 MyBB Group.