On Aug 12, 2011, at 15:29, aortizhi wrote:
> On Aug 11, 5:30 pm, Ryan Schmidt <[email protected]> wrote:
>> On Aug 10, 2011, at 11:45, aortizhi wrote:
>>
>>> Hi eveyone, i'm new working with cakephp. I would like to know how can
>>> i let my webapp's users add new fields to a table in my data base but
>>> while is in production.
>>
>> That's not usually done. Why do you believe you want to do this? What
>> problem are you trying to solve? Perhaps there is a better way.
>
> that's an application's request made for the client. He would like to
> add new information to a table or many tables because there could be
> more information in the future that may came out.
Clients often request things without knowing what they're talking about. :)
It's up to you as the developer to translate their need into a technical
solution that makes sense within the context of the development environment
you're using.
As you're no doubt aware, the usual way to write an app with CakePHP is for the
CakePHP app to have intimate knowledge of the database. Each database table is
represented by a CakePHP model file, and each column in the table has specific
settings in the model, regarding validation and so forth. And each view that
deals with this model knows about those fields as well and has specific ways
and places to display them. It's completely outside the scope of this line of
thinking to imagine a user being able to arbitrarily add a column to a table
and have it just work without needing to also do a lot of reprogramming in the
app's code.
Not to mention that contemplating allowing a web user to alter a database table
is just a nightmare in terms of security. The database user PHP is connecting
with shouldn't even have permission to alter a table. If the user can add
columns, can they also delete columns? What if they delete an essential column?
No, clearly, allowing an end user to alter your database tables is not a course
of action you should consider.
So again: what is the table? What kind of information is in the table? What
kind of additional information that is not in the table now does the client
think they will need to add? Can you give examples?
If I were designing an app that must allow the user to add arbitrary
information to a record, I'd probably have two tables: one for the static
information—the information each record will definitely have—and a second table
for each additional piece of optional data a user might add. For example,
consider an app for tracking houses for sale. I might have table "houses" with
basic information about the house, and "house_extras" which would just have an
additional key/value pair. There could be multiple house_extras records for
each house record. They'd be linked by the house_id.
Table houses ("house_id" is primary key)
house_id: 5
house_address: 123 main street
house_price: 123,456.00
Table house_extras ("house_id + key" is primary key, or at least has a unique
index)
house_id: 5
key: garden
value: ugly
house_id: 5
key: neighbors
value: obnoxious
--
Our newest site for the community: CakePHP Video Tutorials
http://tv.cakephp.org
Check out the new CakePHP Questions site http://ask.cakephp.org and help others
with their CakePHP related questions.
To unsubscribe from this group, send email to
[email protected] For more options, visit this group at
http://groups.google.com/group/cake-php