• 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


Messages In This Thread
redirect() - by donpwinston - 04-19-2017, 01:11 PM
RE: redirect() - by donpwinston - 04-19-2017, 01:29 PM
RE: redirect() - by kilishan - 04-19-2017, 07:17 PM
RE: redirect() - by kilishan - 04-19-2017, 08:06 PM

Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


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