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: init of $data arrays in controllers #2933

Closed
Conspir3D opened this issue May 5, 2020 · 3 comments
Closed

Bug: init of $data arrays in controllers #2933

Conspir3D opened this issue May 5, 2020 · 3 comments
Labels
bug Verified issues on the current code behavior or pull requests that will fix them

Comments

@Conspir3D
Copy link

Conspir3D commented May 5, 2020

Description
When you fill an array in a controller function, typically the $data array, and the first value is a returned array from a models function, the key won't be populated. look at expected behaviour

CodeIgniter 4 version
4.0.3

Affected module(s)
Seems that the bug is somwhere around controller/modell package

Expected behavior, and steps to reproduce if appropriate
not working, $data['data'] is not populated at 'page' view:

$data['data'] = $model->getData($id);
$data['title'] = 'Page for '.$data['data']['dataname'];
$data['something'] = 'else';

echo view('page', $data);

working, $data['data'] is populated at 'page' view:

$data['something'] = 'else';
$data['data'] = $model->getData($id);
$data['title'] = 'Page for '.$data['data']['dataname'];

echo view('page', $data);

Context

  • OS: Debian Linux 10
  • Web server Apache2
  • PHP version 7.3
@Conspir3D Conspir3D added the bug Verified issues on the current code behavior or pull requests that will fix them label May 5, 2020
@nyufeng
Copy link
Contributor

nyufeng commented May 6, 2020

Can you var_dump($data) show data? I want know $data['data'] value type.
image
image
image

@samsonasik
Copy link
Member

$data in the view is refer to 'data' key, not the $data in the controller, so, you can call in the view:

echo $data['dataname'];

@michalsn
Copy link
Member

Not a bug.

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