Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug: saveData option doesn't work in Views #2818

Closed
njsx opened this issue Apr 10, 2020 · 3 comments
Closed

Bug: saveData option doesn't work in Views #2818

njsx opened this issue Apr 10, 2020 · 3 comments
Labels
bug Verified issues on the current code behavior or pull requests that will fix them
Milestone

Comments

@njsx
Copy link

njsx commented Apr 10, 2020

I have a two views header.php and footer.php with a same content:

<h3><?= $title ?></h3>

In my Controller I have this code:


public function index() {

      $data['title'] = "Welcome!";

      echo view('header', $data);

      echo view('footer');


When I call this Controller I can see on my screen:
Welcome! Welcome!

In App\Config\View.php I set:
public $saveData = false; (or true doesn't matter)

In the UserManual

If you call the function multiple times in a single request, you will have to pass the desired data to each view.

Regardless of the transmitted values, this parameter does not work!!! I always see the same thing!

@njsx njsx added the bug Verified issues on the current code behavior or pull requests that will fix them label Apr 10, 2020
@diolan12
Copy link

Never try using double view call like yours.
I use once in my controller, just for load the main view.
Because I'm using return, not echo.
Then I load bunch of header or footer etc inside view.

app/Controllers/Main.php

public function index() {
  $data = array(
    'title' => 'Hello World!',
    'header' => array(
      'greet' = 'Welcome!'
    ),
    'footer' => array(
      'copyright' => 2020
    )
  );
  return view('welcome_message', $data);
}

app/Views/welcome_message.php

<html>
  <head>
    <title><?= $title?></title>
  </head>
  <body>
    <?= view('header', $header)?>
    <?= view('footer', $footer)?>
  </body>
</html>

app/Views/header.php

<head>
  <h3><?= $greet?></h3>
</head>

app/Views/footer.php

<footer>
  <p>Copyright <?= $copyright?></p>
</footer>

Notice how I load another view:
<?= view('some_view', $array)?>

It is easier to read by human, not just a bunch of hundreds or even thousands of code in one file.

@njsx
Copy link
Author

njsx commented Apr 10, 2020

Sorry for my bad English...But I try to answer.

I do any projects also as you and I never use multiple times call the function in a single request, but the problem is not in this! The problem is that the stated feature in the user guide DOES not WORK! I am translating official documentation into Russian and I need to tell the community about how this function works. To illustrate by examples, but the examples don'T WORK! That's why I report the problem to the developers.

@iRedds
Copy link
Collaborator

iRedds commented Apr 12, 2020

I confirm a bug in system\Common.php function view()

$saveData = true;
if (array_key_exists('saveData', $options) && $options['saveData'] === true)
{
	$saveData = (bool) $options['saveData'];
	unset($options['saveData']);
}

Variable $saveData will always be true. Which means View::$saveData will always be assigned true

@lonnieezell lonnieezell added this to the 4.0.3 milestone Apr 21, 2020
@nyufeng nyufeng mentioned this issue Apr 21, 2020
5 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Verified issues on the current code behavior or pull requests that will fix them
Projects
None yet
Development

No branches or pull requests

4 participants