Welcome Guest, Not a member yet? Register   Sign In
CI4 lacks seems to lack a couple of super convenient CI3 features.
#1

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

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

(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?
Reply
#4

(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, www.ignitedcms.com
Reply
#5

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

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

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

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

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

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




Theme © iAndrew 2016 - Forum software by © MyBB