how do I pass an array to the View from the controller?

Viewed 19

If the values entered in the fields are incorrect, an error should be output, which is written to the array in the Controller and given to the View. The value in array is recorded, but the View does not show it. I understand that some kind of reload is needed, but how to write it?

controller_login.php

class controller_login extends Controller
{
    public function __construct()
    {
        $this->model = new model_login();
        $this->view = new View();
    }
    function action_index()
    {
        $this->pageData['title'] = "Sign In";
        if (!empty($_POST)) {
            $action = $_POST['action'];

            if ($action == 'login') {
                if (!$this->model->entry()) {
                    $this->pageData['loginError'] = "Incorrect login or password";
                }
            }
        } else {
            $this->view->non_template("login_view.php", $this->pageData); // here
        }
    }
}

login_view.php

<input type="hidden" name="action" value="login">
                    <?php if (!empty($pageData['loginError'])) : ?>
                        <p class="color-red"><?php echo $pageData['loginError']; ?></p>
                    <?php endif; ?>
0 Answers
Related