CodeIgniter Forums
CI4 lacks seems to lack a couple of super convenient CI3 features. - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: CodeIgniter 4 (https://forum.codeigniter.com/forumdisplay.php?fid=28)
+--- Forum: CodeIgniter 4 Discussion (https://forum.codeigniter.com/forumdisplay.php?fid=31)
+--- Thread: CI4 lacks seems to lack a couple of super convenient CI3 features. (/showthread.php?tid=71819)



CI4 lacks seems to lack a couple of super convenient CI3 features. - skunkbad - 09-27-2018

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.


RE: CI4 lacks seems to lack a couple of super convenient CI3 features. - ignitedcms - 09-27-2018

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.


RE: CI4 lacks seems to lack a couple of super convenient CI3 features. - skunkbad - 09-28-2018

(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?


RE: CI4 lacks seems to lack a couple of super convenient CI3 features. - ignitedcms - 09-28-2018

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


RE: CI4 lacks seems to lack a couple of super convenient CI3 features. - ciadmin - 09-28-2018

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/outgoing/view_renderer.html#class-reference

... specifically, the setVar and setData methods of any view or view parser.


RE: CI4 lacks seems to lack a couple of super convenient CI3 features. - Pertti - 09-28-2018

(09-28-2018, 12:45 AM)ciadmin Wrote: Re (2), is this what you are looking for? https://bcit-ci.github.io/CodeIgniter4/outgoing/view_renderer.html#class-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.


RE: CI4 lacks seems to lack a couple of super convenient CI3 features. - unodepiera - 09-28-2018

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/general/configuration.html?highlight=config

For load vars globally, I love Blade Engine, tested with CodeIgniter 4 works really fine.


RE: CI4 lacks seems to lack a couple of super convenient CI3 features. - dave friend - 09-28-2018

(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.


RE: CI4 lacks seems to lack a couple of super convenient CI3 features. - skunkbad - 09-28-2018

(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/outgoing/view_renderer.html#class-reference

... specifically, the setVar and setData methods of any view or view parser.

Thank you. This looks like exactly what I need.


RE: CI4 lacks seems to lack a couple of super convenient CI3 features. - skunkbad - 09-28-2018

(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.