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

New feature for the issue #551 #552

Merged
merged 4 commits into from
Dec 26, 2024
Merged

New feature for the issue #551 #552

merged 4 commits into from
Dec 26, 2024

Conversation

evil1
Copy link
Contributor

@evil1 evil1 commented Dec 25, 2024

Q A
Is bugfix?
New feature? ✔️
Breaks BC?
Fixed issues #551

Copy link
Member

@samdark samdark left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add a line to CHANGELOG. Thanks.

@evil1
Copy link
Contributor Author

evil1 commented Dec 26, 2024

Please add a line to CHANGELOG. Thanks.

Done

@samdark
Copy link
Member

samdark commented Dec 26, 2024

Forgot to push?

@evil1
Copy link
Contributor Author

evil1 commented Dec 26, 2024

Forgot to push?

Added changelog to another issue, related to yiisoft/db :).
Second try. Now it's done for sure.

@samdark samdark merged commit 3e270e1 into yiisoft:master Dec 26, 2024
11 checks passed
@samdark samdark added this to the 2.2.7 milestone Dec 26, 2024
@samdark
Copy link
Member

samdark commented Dec 26, 2024

Thank you!

@rob006
Copy link
Contributor

rob006 commented Dec 29, 2024

I don't get it. By default formName() is used as form name in load() and while generating inputs. After this change form name is specified explicitly for load(), but for inputs generation value from formName() is still used. So if you want to change form name you need to change it in two places now?

@samdark
Copy link
Member

samdark commented Dec 29, 2024

@evil1 ?

@evil1
Copy link
Contributor Author

evil1 commented Dec 30, 2024

I don't get it. By default formName() is used as form name in load() and while generating inputs. After this change form name is specified explicitly for load(), but for inputs generation value from formName() is still used. So if you want to change form name you need to change it in two places now?

formName() returns a class name (via ReflectionClass::getShortName() under the hood).
We are explicitly passing the same class name, to be able to pass custom form name (especially empty string) to the search() method, and pass it to load method.
Why do we have to change it somewhere else?

When you receive the data from Yii form you have attributes LoginForm[login] and LoginForm[password].
When we use model to accept data from API it's redundant to always append form name to each attribute.
Instead of this we pass clean attributes login and password, and empty string as a form name.

$data = [
    'login' => 'my_login',
    'password' => 'some_complex_password',
];

$loginForm->load($data, '');

The above example is not 100% correct, because normally you don't need a search model at all for login flow. But it illustapes well what happens and why do we need it as is. Normaly we would use search model for sorting, filering and pagination, but the idea behind it is exactly the same

@rob006
Copy link
Contributor

rob006 commented Dec 30, 2024

formName() returns a class name (via ReflectionClass::getShortName() under the hood).

formName() could be overwritten. Previously if I wanted to remove form name from search form, all I needed is to overwrite formName() to return empty string - new value was respected both in view with search form and in load(). Now it is not enough - I also need to change default param value in search(), because search() ignores formName() after this PR.

So this solution is suboptimal for code that Gii generates, just to cover hypothetical (and IMO quite niche) use case.

@evil1
Copy link
Contributor Author

evil1 commented Dec 30, 2024

Got it. Should I revert this PR back?

@rob006
Copy link
Contributor

rob006 commented Dec 30, 2024

Changing method signature to search($params, $formName = null) should fix the problem I mentioned in #552 (comment). But I'm still not sure if this use case is common enough to have it in default template.

@evil1
Copy link
Contributor Author

evil1 commented Jan 4, 2025

Should I submit new PR to fix this issue?

@samdark
Copy link
Member

samdark commented Jan 4, 2025

Yes. Please.

@evil1
Copy link
Contributor Author

evil1 commented Jan 5, 2025

Yes. Please.

Added a PR here. Set $formName = null as advised by @rob006

samdark added a commit that referenced this pull request Jan 6, 2025
Co-authored-by: Robert Korulczyk <robert@korulczyk.pl>
Co-authored-by: Alexander Makarov <sam@rmcreative.ru>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants