• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How do you access the $this bound data of the controller in the view? Ci3 is OK, ci4

#1
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?
Reply

#2
Lonnie blogged about some of the super object & dependency injection, back in 2016. It might be informative...
http://blog.newmythmedia.com/blog/show/2...eIgniter_4

There was community discussion about this, in 2015, with mixed opinions...
https://forum.codeigniter.com/thread-613...per+object
Reply

#3
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.
Reply

#4
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.
Reply

#5
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.
Reply

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

#7
ok,Thank you!
Reply

#8
(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.
Reply


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2020 MyBB Group.