CodeIgniter Forums
How do you access the $this bound data of the controller in the view? Ci3 is OK, ci4 - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: CodeIgniter 4 (https://forum.codeigniter.com/forum-28.html)
+--- Forum: CodeIgniter 4 Discussion (https://forum.codeigniter.com/forum-31.html)
+--- Thread: How do you access the $this bound data of the controller in the view? Ci3 is OK, ci4 (/thread-69145.html)



How do you access the $this bound data of the controller in the view? Ci3 is OK, ci4 - miaojun - 10-13-2017

How do you access the $this bound data of the controller in the view? Ci3 is OK, ci4 doesn't seem to work

souch as ci3's get_instance()

I can use the global $this anywhere in the controller, model, view in CI3, but ci4, I can't use the global $this in the view, the model, which worries me

get_instance is not available because there is no "super object" aka singleton is present in ci4.

but , in Ci4 'view and model or other , How do I get $this?

I want to write some PHP code in view, which is more convenient,If I don't get $this, all the data can only pass into the view in the echo view ($data) value of the controller, which will be too inconvenient. Is there any way?


RE: How do you access the $this bound data of the controller in the view? Ci3 is OK, ci4 - ciadmin - 10-13-2017

Lonnie blogged about some of the super object & dependency injection, back in 2016. It might be informative...
http://blog.newmythmedia.com/blog/show/2016-03-04_Dependency_Injection_in_CodeIgniter_4

There was community discussion about this, in 2015, with mixed opinions...
https://forum.codeigniter.com/thread-61345.html?highlight=super+object


RE: How do you access the $this bound data of the controller in the view? Ci3 is OK, ci4 - miaojun - 10-14-2017

I looked carefully at the articles you gave me, but I still couldn't get the content of $this from view.

I just want to get the content of the $this inherited by the current controller in view, but I can't get it.


RE: How do you access the $this bound data of the controller in the view? Ci3 is OK, ci4 - kilishan - 10-15-2017

You won't be able to get access to anything in the controller unless it's passed to the view. Any data you want in the view should be passed to it.


RE: How do you access the $this bound data of the controller in the view? Ci3 is OK, ci4 - miaojun - 10-16-2017

I use CI development background management system, in the view to write some business will be more convenient.

But I've solved this problem, and I've rebuilt the view function.

Thanks.


RE: How do you access the $this bound data of the controller in the view? Ci3 is OK, ci4 - kilishan - 10-16-2017

I forgot to mention it previously, but View Cells might be helpful for you.


RE: How do you access the $this bound data of the controller in the view? Ci3 is OK, ci4 - miaojun - 10-17-2017

ok,Thank you!


RE: How do you access the $this bound data of the controller in the view? Ci3 is OK, ci4 - tereaksmey123 - 10-20-2017

(10-15-2017, 07:26 PM)kilishan Wrote: You won't be able to get access to anything in the controller unless it's passed to the view. Any data you want in the view should be passed to it.

hi does it mean i can't pass Value in my Base_controller to view or controller anymore in CI4 ? like this code

Base_controller
Code:
$this->tbl_slide = 'tbl_slide';
$this->tbl_user = 'tbl_user';


/* Session language */
$this->my_lang = $this->session->userdata('camfone_lang_file') ?? 'khmer';
$this->lang->load("{$this->my_lang}_lang", $this->my_lang);
$this->my_prefix = $this->session->userdata('camfone_prefix') ?? '_kh';


so i can't call $this->my_prefix in my view or other Controller anymore in CI4 ? 
Thank in advance.