Link to home
Start Free TrialLog in
Avatar of Ramy Mohsen
Ramy Mohsen

asked on

Yii2, I want to make the input names to be not the same as db fields

Hello,

In yii2, I want to make DB fields not the same as input fields, but the auto generated code from Gii makes them the same,

When I manually change name of the input fields, It shows an error, How can I map the changed input names to the corresponding fields

Regards,
Avatar of Loganathan Natarajan
Loganathan Natarajan
Flag of India image

Can you post the form fields here?  Usually Gii will generate as per the db fields with $model appended  like http://www.yiiframework.com/doc-2.0/guide-input-forms.html
No points for this because it's not an answer to your question, but I'm moved to ask WTF?  This sounds theoretically possible using some kind of facade or translator, but given the context of Yii2, it sounds like a way to add complexity without adding functionality, at the potential risk of losing the benefits of active record design.  If this were my application I would seriously reconsider...
I wouldn't do that either.  Rather I should say, I normally make them the same on purpose so I know how the database fields correlate with the input fields.
Avatar of Ramy Mohsen
Ramy Mohsen

ASKER

Thank you all,

My cause for that is that I don't want anyone to be able to guess names of the fields in the DB (better security ),  so just I make the db  fields to be prefixed.

For example:  DB fields may be named:  XYZ_username, XYZ_password, while the input names named : username, password

Thanks in advance,
Munging your database column names is not a security measure.  

You've got the advice from the experience of the top Experts, so I will sign off.  If you want to learn about security issues that really matter, start here:
http://php.net/manual/en/security.php
http://www.yiiframework.com/doc-2.0/yii-base-security.html

Also, consider becoming active in OWASP.
https://www.owasp.org/index.php/Main_Page
ASKER CERTIFIED SOLUTION
Avatar of Loganathan Natarajan
Loganathan Natarajan
Flag of India image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial