Welcome Guest, Not a member yet? Register   Sign In
Proper way to get array from session
#7

(This post was last modified: 04-20-2021, 01:02 AM by iRedds.)

I will show you an example of how you can get out of this situation.
PHP Code:
// route 
$routes->add('/''Home::index');
// in controller 
public function index()
{
    if (
$this->request->getMethod() !== 'get') {
        if (! 
$this->validate(['a.c' => 'required'])) {
            return 
redirect()->to('/')->withInput();
        } else {
            
d('win');
        }

    } else {
        
session(); 
        return 
view('template', ['validator' => Services::validation()]);
    }
}
// template
<?php /** @var Codeigniter\Validation\Validation $validator */ ?>
<h1>error: <?= $validator->getError('a.c')?></h1>
<form method="post" action="/">
    <input type="text" name="a[b]" value="aa">
    <input type="submit">
</form> 

Anyway, I added a PR to access the key containing the dot using dot notation.
https://github.com/codeigniter4/CodeIgniter4/pull/4588
Reply


Messages In This Thread
RE: Proper way to get array from session - by iRedds - 04-20-2021, 12:59 AM



Theme © iAndrew 2016 - Forum software by © MyBB