CI4 lacks seems to lack a couple of super convenient CI3 features. |
I'll come right out and say that I have not read the entire manual, but here is what I love in CI3 and don't find it in CI4:
1) Adding something to config so I can use it anywhere. I'm talking about $this->config->set_item() and then later being about to use config_item() to get the value. This was super handy, as one could pass values to almost anywhere. 2) Adding vars to views with $this->load->vars(). Similar to config->set_item(), being able to set vars that were available in any view was really handy in CI3. Please let me know your CI4 secrets.
I can't speak for the new authors but this could be by design, what with everyone pushing modular code globals are often frowned upon. As you know I've been working with nodejs and most frameworks require you to use the 'use strict' declaration which implicitly forbids global variables.
I haven't used globals in years.
Practical guide to IgnitedCMS - Book coming soon, www.ignitedcms.com
(09-27-2018, 11:22 PM)ignitedcms Wrote: I can't speak for the new authors but this could be by design, what with everyone pushing modular code globals are often frowned upon. As you know I've been working with nodejs and most frameworks require you to use the 'use strict' declaration which implicitly forbids global variables. Nothing about CI3 config items or view Vars has anything to do with global variables. In the case of config items, they are retrieved with a function call. Loading view Vars only allows them to be available in views. CI always provided maximum flexibility, even to the point where it could be used terribly wrong. Now all the sudden we have a nanny?
You're right, I made a mistake thinking they were globals or a wrapper for a constant or something, I guess we will wait for @kilishan to let us know what the plans are
Practical guide to IgnitedCMS - Book coming soon, www.ignitedcms.com
Re (1), is this what you are looking for? ... you can have method scope
Code: $app = config('App'); Code: $this->app = config('App'); You can access anything from application/Config/App (or whichever config file you are interested in), and you can even create config items on the fly. The pre-existing ones are supposed to be static, so instance-agnostic. If you wanted the same for yours, then add it to App similarly. Re (2), is this what you are looking for? https://bcit-ci.github.io/CodeIgniter4/o...-reference ... specifically, the setVar and setData methods of any view or view parser. (09-28-2018, 12:45 AM)ciadmin Wrote: Re (2), is this what you are looking for? https://bcit-ci.github.io/CodeIgniter4/o...-reference Ah, automatically escaping variables, unless you explicitly tell it not to - that'll be super useful saving time having to what htmlspecialchar() around all the echo statements.
Hi skunkbak, for set and get configuration files you can do it like said ciadmin:
PHP Code: $appConfig = \config('app'); https://bcit-ci.github.io/CodeIgniter4/g...ght=config For load vars globally, I love Blade Engine, tested with CodeIgniter 4 works really fine.
(09-27-2018, 10:58 PM)skunkbad Wrote: 2) Adding vars to views with $this->load->vars(). Similar to config->set_item(), being able to set vars that were available in any view was really handy in CI3. The default "renderer" service is an instance of \CodeIgniter\View\View and that class has both setVar and setData methods. The part I haven't yet come to terms with yet is the default behavior of not maintaining the "view data" between calls to view(). Due to ingrained habits, I may opt for setting $saveData to true in application/Config/Views.php which is supposed to make view() behave in the traditional way. I've never understood the concern about data "bleeding" into other views. (09-28-2018, 12:45 AM)ciadmin Wrote: Re (1), is this what you are looking for? ... you can have method scope Thank you. This looks like exactly what I need. (09-28-2018, 07:16 AM)dave friend Wrote:(09-27-2018, 10:58 PM)skunkbad Wrote: 2) Adding vars to views with $this->load->vars(). Similar to config->set_item(), being able to set vars that were available in any view was really handy in CI3. I'm seeing saveData set to true by default. I'm glad you told me about that though, as that's how I expect it to behave. |
Welcome Guest, Not a member yet? Register Sign In |