thephpleague / plates

Native PHP template system
https://platesphp.com
MIT License
1.47k stars 180 forks source link

set and get dynamic data array #226

Closed S3lfC0d3r closed 6 years ago

S3lfC0d3r commented 6 years ago

My validate login form print this array:

Array
(
    [0] => The Customer Name field is required
    [1] => The Customer Password field is required
    [2] => The Email field is required
    [3] => The Gender field is required
    [4] => The Credit Card field is required
)

how do can i send data to login/index using addData method like this:

    $this->templates->addData([`??` ], 'login/index');

and get in login index?!

Thanks for any help

napec commented 6 years ago
$errors = [
    'The Customer Name field is required',
    'The Customer Password field is required',
    // ....
];

/** @var \League\Plates\Engine $engine */
$engine->addData(['errors' => $errors], 'login/index');
// or...
$engine->render('login/index', ['errors' => $errors]);

...in your [path_to_templates]/login/index.php

<?php foreach ($errors as $error): ?>
    <?=$error ?><br>
<?php endforeach ?>
ragboyjr commented 6 years ago

@napec Thank you for your response. @S3lfC0d3r @napec's response is precisely the way to go about this.

If you have any other issues let me know, otherwise, i'll close this issue. Thanks!

S3lfC0d3r commented 6 years ago

@napec @ragboyjr Sorry For delay Im so Busy..

Thanks @napec Good Work.