Posts: 1,299
Threads: 62
Joined: Oct 2014
Reputation:
86
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.
Posts: 414
Threads: 62
Joined: Jul 2015
Reputation:
6
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
Posts: 1,299
Threads: 62
Joined: Oct 2014
Reputation:
86
(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.
I haven't used globals in years.
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?
Posts: 414
Threads: 62
Joined: Jul 2015
Reputation:
6
09-28-2018, 12:20 AM
(This post was last modified: 09-28-2018, 12:29 AM by ignitedcms.)
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
Posts: 1,321
Threads: 21
Joined: Jan 2014
Reputation:
70
Re (1), is this what you are looking for? ... you can have method scope
Code: $app = config('App');
$app->brian = 'whatever you want';
Or, if you want to access it everywhere, give it object scope,
Code: $this->app = config('App');
$this->app->brian = 'whatever you want';
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.
Posts: 365
Threads: 5
Joined: May 2015
Reputation:
32
(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
... specifically, the setVar and setData methods of any view or view parser.
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.
Posts: 20
Threads: 1
Joined: Nov 2014
Reputation:
3
09-28-2018, 04:22 AM
(This post was last modified: 09-28-2018, 04:30 AM by unodepiera.)
Hi skunkbak, for set and get configuration files you can do it like said ciadmin:
PHP Code: $appConfig = \config('app'); $appConfig->CSPEnabled = true;
https://bcit-ci.github.io/CodeIgniter4/g...ght=config
For load vars globally, I love Blade Engine, tested with CodeIgniter 4 works really fine.
Posts: 1,020
Threads: 15
Joined: Jun 2015
Reputation:
50
(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.
Posts: 1,299
Threads: 62
Joined: Oct 2014
Reputation:
86
(09-28-2018, 12:45 AM)ciadmin Wrote: Re (1), is this what you are looking for? ... you can have method scope
Code: $app = config('App');
$app->brian = 'whatever you want';
Or, if you want to access it everywhere, give it object scope,
Code: $this->app = config('App');
$this->app->brian = 'whatever you want';
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.
Thank you. This looks like exactly what I need.
Posts: 1,299
Threads: 62
Joined: Oct 2014
Reputation:
86
(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.
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.
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.
|