• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Invalid argument supplied for foreach() when using parser

#1
hello all, Im just moving from CI3 to CI4 , im still playing around with it and;
here some code example

in my controller auth.php
PHP Code:
<?php

namespace App\Controllers;

class 
Auth extends BaseController
{
    public function index($ext null)
    {
        $data = [
            'submit_url'        => base_url('auth/submit'),
            'error'             => $ext['error'],
            'csrf_token'        => csrf_token(),
            'csrf_hash'         => csrf_hash()
        ];
        echo view('inc/header');
        echo $this->parser->setData($data)->render('auth');
        echo view('inc/footer');
    }

    public function submit()
    {
        $this->validation->setRules([
            'email'         => 'required|valid_email',
            'password'      => 'required',
        ]);
        $valid $this->validation->withRequest($this->request)->run();
        if ($valid === false) {
            $ext = [
                'error' => $this->validation->getErrors(),
            ];
            return $this->index($ext);
        }
        $email $this->request->getPost('email');
        return $email;
    }


in my view auth.php
PHP Code:
{error}
{
email}
{
password}
{/
error}

<
form class="ui form" method="post" action="{submit_url}">
    <div class="field">
        <label>Email</label>
        <input type="text" name="email" placeholder="Email">
    </div>
    <div class="field">
        <label>Password</label>
        <input type="password" name="password" placeholder="Password">
    </div>
    <input type="hidden" name="{csrf_token}" value="{csrf_hash}" />
    <button class="ui button" type="submit">Submit</button>
</
form


but i get this error after try surfing the page
   


it is same like i did in CI3 when using parser, hope someone can help me. thank you
Reply

#2
What is the value of $ext['error'] ? Any chance it's a string?
Support Development  • Practical CodeIgniter 3  •
Myth:AuthVulcan - CLI Tools for CI4
Reply

#3
(01-26-2020, 10:31 PM)kilishan Wrote: What is the value of $ext['error'] ? Any chance it's a string?
 
first of all, thanks for replying

so I did a var_dump var $data

here I get:-

Code:
array(4) {
  ["submit_url"]=>
  string(47) "http://192.168.1.103/test/public/auth/submit"
  ["error"]=>
  array(2) {
    ["email"]=>
    string(28) "The email field is required."
    ["password"]=>
    string(31) "The password field is required."
  }
  ["csrf_token"]=>
  string(12) "csrf_test"
  ["csrf_hash"]=>
  string(32) "154e1de7b3679b11720940ce8e6cc2ae"
}
Reply


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


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