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

Bug: [Parser] NumberFormatter::setAttribute Passing null to parameter #2 ($value) of type int|float is deprecated #7156

Closed
bedrijfsportaal opened this issue Jan 20, 2023 · 20 comments · Fixed by #7157
Assignees
Labels
bug Verified issues on the current code behavior or pull requests that will fix them

Comments

@bedrijfsportaal
Copy link

PHP Version

8.0

CodeIgniter4 Version

4.3.1

CodeIgniter4 Installation Method

Composer (using codeigniter4/appstarter)

Which operating systems have you tested for this bug?

Windows

Which server did you use?

cli-server (PHP built-in webserver)

Database

MariaDB 10.4.24

What happened?

Using the service::render with { price|local_currency(eur,nl_NL) } is not working, the fraction option cannot be set and doesn't accept null value.

Error NumberFormatter::setAttribute(): Passing null to parameter #2 ($value) of type int|float is deprecated

Steps to Reproduce

Render view with { price|local_currency(eur,nl_NL) } as option.

Expected Output

Be able to set the fraction like { price|local_currency(eur,2,nl_NL) }

Anything else?

No response

@bedrijfsportaal bedrijfsportaal added the bug Verified issues on the current code behavior or pull requests that will fix them label Jan 20, 2023
@bedrijfsportaal
Copy link
Author

bedrijfsportaal commented Jan 20, 2023

Found the issue for my problem, the documentation is missing a third parameter, it's allowed to use the following way { price|local_currency(eur,nl_NL,2) } so the fraction is set. But the issue remains if you don't set the third parameter, the error will still be thrown.

<!-- This works -->
{ price|local_currency(eur,nl_NL,2) }

<!-- This will throw ErrorException -->
{ price|local_currency(eur,nl_NL) }

Edit

Missing the option to set the default view path on initialize as well, had to find out by digging to the code that it's allowed to change the view path.

$render = Services::parser( $viewPath = null, $config = null, $getShared = true );

@kenjis
Copy link
Member

kenjis commented Jan 21, 2023

Thank you for reporting.
I sent a PR: #7157

@kenjis
Copy link
Member

kenjis commented Jan 21, 2023

Missing the option to set the default view path on initialize as well, had to find out by digging to the code that it's allowed to change the view path.

What do you mean?
Why do you need to change the view path?

@bedrijfsportaal
Copy link
Author

In my case i work from a modules folder inside the app folder, example:

App
-- Modules
---- Modulename
------- Views

By default it looks at:

App
-- Views

@kenjis
Copy link
Member

kenjis commented Jan 21, 2023

You can use Namespaced Views.
See https://codeigniter4.github.io/CodeIgniter4/outgoing/views.html#namespaced-views

But you mean you want to write code like view('blog_view')?

@bedrijfsportaal
Copy link
Author

You can use Namespaced Views. See https://codeigniter4.github.io/CodeIgniter4/outgoing/views.html#namespaced-views

But you mean you want to write code like view('blog_view')?

I think it's a misunderstanding from my side, i'm using the https://codeigniter4.github.io/CodeIgniter4/outgoing/view_renderer.html#CodeIgniter\View\View that doesn't work with Namespaces.

@kenjis
Copy link
Member

kenjis commented Jan 21, 2023

Did you define the namespace for the module?
See https://codeigniter4.github.io/CodeIgniter4/general/modules.html#namespaces

view() calls CodeIgniter\View\View::render() inside.
So Namespaced Views also should work.

@bedrijfsportaal
Copy link
Author

Did you define the namespace for the module? See https://codeigniter4.github.io/CodeIgniter4/general/modules.html#namespaces

view() calls CodeIgniter\View\View::render() inside. So Namespaced Views also should work.

Yes, these are defined in App\Config\Autoload.php

I've returned CodeIgniter\View\View::render, this doesn't set the Namespace, except when using the below option.

$render = Services::parsert( '\App\Modules\ModuleName' );

// With this I can use
return $render->setData(['key' => 'val'])->render('view_name');

@kenjis
Copy link
Member

kenjis commented Jan 23, 2023

I mean namespaced view is like view('Example\Blog\Views\blog_view').
So in your case, return $render->setData(['key' => 'val'])->render('App\Modules\ModuleName\Views\view_name')

@bedrijfsportaal
Copy link
Author

I mean namespaced view is like view('Example\Blog\Views\blog_view'). So in your case, return $render->setData(['key' => 'val'])->render('App\Modules\ModuleName\Views\view_name')

This in my case wil result in a ErrorException and by default looks at App\Views\view_name.php when using:

// Will by default look in: App\Views\view_name.php
return $render->setData(['key' => 'val'])->render('view_name');

@kenjis
Copy link
Member

kenjis commented Jan 23, 2023

No, I mean:

return $render->setData(['key' => 'val'])->render('App\Modules\ModuleName\Views\view_name');

@bedrijfsportaal
Copy link
Author

No, I mean:

return $render->setData(['key' => 'val'])->render('App\Modules\ModuleName\Views\view_name');

That will result in the error given below:

CodeIgniter\View\Exceptions\ViewException
Invalid file: "C:\***\app\Config/../Views\App\Modules\Bookings\Views\order_template.php"

@kenjis
Copy link
Member

kenjis commented Jan 23, 2023

@bedrijfsportaal
Copy link
Author

bedrijfsportaal commented Jan 23, 2023

@bedrijfsportaal Cannot reproduce.

The following code works fine: https://github.com/kenjis/ci4-modules-test/blob/44ecb00875aead3d240f09f81f50338ce94dec3e/modules/Home/src/Controllers/Home.php#L37

This repository code does not work on your Windows? https://github.com/kenjis/ci4-modules-test Navigate to http://localhost:8080/parser

My folder structure differs from your example, but i've found the issue myself working just like you answered!
Looked like my namespace had a very small typo (almost did not see it), after running tests i've been able to find out.

@kenjis
Copy link
Member

kenjis commented Jan 24, 2023

Good to hear.

As you say, the following is not documented.

$render = Services::parser('/path/to/Views');
$render = Services::renderer('/path/to/Views');

It seems better to be documented in the user guide.

@kenjis
Copy link
Member

kenjis commented Jan 24, 2023

Ah, it seems the following code worked, but it is still a misuse.

$render = Services::parser( '\App\Modules\ModuleName' );

Because the $viewPath is the directory, not a namespace.

* The base directory to look in for our Views.
*
* @var string
*/
protected $viewPath;

@kenjis kenjis changed the title Bug: NumberFormatter::setAttribute Passing null to parameter #2 ($value) of type int|float is deprecated Bug: [Parser] NumberFormatter::setAttribute Passing null to parameter #2 ($value) of type int|float is deprecated Jan 24, 2023
@bedrijfsportaal
Copy link
Author

Ah, it seems the following code worked, but it is still a misuse.

$render = Services::parser( '\App\Modules\ModuleName' );

Because the $viewPath is the directory, not a namespace.

* The base directory to look in for our Views.
*
* @var string
*/
protected $viewPath;

Ah dammit, your right totally overlooked that part...
Using it as a file path does the trick as well like you've mentioned.

Thank you for the clearifycation, will keep this in mind for other modules!

@kenjis
Copy link
Member

kenjis commented Jan 24, 2023

I found a bug that the following does not work, because the debugbar initialize the shared renderer service.

$render = Services::renderer('/path/to/Views');

I sent a PR to fix #7172

@bedrijfsportaal
Copy link
Author

I found a bug that the following does not work, because the debugbar initialize the shared renderer service.

$render = Services::renderer('/path/to/Views');

I sent a PR to fix #7172

Debugbar is disabled by default for me, so i wouldn't have noticed that, but good to hear the bug is as quickly fixed as it is found!

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

Successfully merging a pull request may close this issue.

2 participants