Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

set_value does not work with NULL as second parameter #2935

Closed
crustamet opened this issue May 5, 2020 · 7 comments
Closed

set_value does not work with NULL as second parameter #2935

crustamet opened this issue May 5, 2020 · 7 comments
Labels
bug Verified issues on the current code behavior or pull requests that will fix them

Comments

@crustamet
Copy link
Contributor

Hello. im getting this error

Argument 2 passed to set_value() must be of the type string, null given, called in

Yes i know it needs a string but in my database i have a lot of NULL values in columns.
This worked in Codeigniter 3, if it was null it just didn't do anything.

I have to make if case for each input values just to check if it is null or not just to make it work like seriously ?

I am just asking if you guys let it like this forever or it will be changed in near future.

While $item comes from Database and it is a NULL value.

set_value('button', $item['button']);

@crustamet crustamet added the bug Verified issues on the current code behavior or pull requests that will fix them label May 5, 2020
@crustamet
Copy link
Contributor Author

I came across this validation rule that you guys have in your documentation

permit_empty | No | Allows the field to receive an empty array, empty string, null or false.
How this rule work if the set_value does not permit a NULL value ?

@michalsn
Copy link
Member

michalsn commented May 7, 2020

You should cast your variables:

set_value('button', (string) $item['button']);

But maybe if you send a PR with changes, they will be accepted.

About permit_empty - I think we both know that you can't really send null or false value via form :) But you can validate data from various sources, they don't have to come from the form.

@crustamet
Copy link
Contributor Author

Nice bro about the cast i didn't think about this.

About permit_empty yeah you can, you just don`t add the input inside the form.
But set_value always return string even if the input does not exist in the form.

I am sure this is a bug. But it is a weird one.

@michalsn
Copy link
Member

michalsn commented May 7, 2020

permit_empty - I am pretty sure you're mixing string values with actual null and false values.

set_value() always return a string because it supposes to do it.

I don't see a bug here, sorry.

@crustamet
Copy link
Contributor Author

crustamet commented May 7, 2020

Ok man, so it is going to be like this for set_value forever right ?

I mean if there is going to be changed with what i told you.

Because i'm going to make this application that uses this and i'm not going to get back to it and change this set_value if i already made checks on every controller action when i update my CI4.

I have at least 100 Controllers with 5 to 10 actions in each controller.

@crustamet
Copy link
Contributor Author

Please think for a moment when you want to insert into database NULL values when you add an item.
Let's say Banners.

And you want to schedule the banner to appear in some interval then you have Date Start and Date End in form that are disabled by default and then only if you check a button then enables the inputs.

How can i insert them with NULL if the set_value escapes the input and return emtpy. I always have t o check if the input is set and then get the value with set_value.

How can i do this without using this code for example ?

if(set_value('date_end')) $insert['date_end'] = set_value('date_end');

@michalsn
Copy link
Member

michalsn commented May 7, 2020

I think it would be better to start a thread on our forum because it seems to me that this is more like a request for support than a bug.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Verified issues on the current code behavior or pull requests that will fix them
Projects
None yet
Development

No branches or pull requests

2 participants