I recommended using ajax because you wouldn't have to access the
database as much. From the way you describe, it sounds like there will
be many records displayed at the same time on one page. Without Ajax,
each time you submitted, you would have to re-query the data from all
the records on the page instead of just the one that you saved. You
could certainly do it without ajax though.

When you ask if this can be applicable for several models, I'm not
sure what you mean. If you mean that you want multiple models on the
same page, this is easily done. If you mean you want to have the same
view for multiple models you can do this as well, but I'd suggest
creating new views for each model just to keep the code less
complicated. I don't think that you would need to define a behavior or
helper for this.

If I understand you correctly, I don't think the updateAll function
will work for your needs. UpdateAll is great if you want to update all
records with the same data (ie, you have an input field and want the
data submitted with this field to be placed in several different
records) but if you want each record to have independent data, this
won't work.

Also, If you will be often adding new fields I would go with
the_woodsman's suggestion above. Although it's possible to add
physical fields to a database, RDBMS systems like MySQL aren't really
designed to be used this way. Do some data normalization, define a new
table with the following fields: "fieldname, fieldvalue, row_id" and
create a hasMany relationship between it and your model. Whenever you
want to add a new field, insert data into this table with the field
name, value and the row record id that it is associated with. To find
all fields that have already been added, do a query on this table with
GROUP BY fieldname, you can then generate input boxes for each one in
your view and populate them with any existing data. This will be much
easier than actually changing the structure of your database whenever
you want to add a new field.

Dave

On May 6, 8:47 am, SumanRS <[EMAIL PROTECTED]> wrote:
> Thanks, this is along the lines of what I am looking for.
>
> Why AJAX though? Is it possible for me to list all rows and have an
> editable textfield for only the new field I added? If so, would
> updateAll() work as in grigri's idea?
>
> Also, if I wanted to make this applicable for several models, would I
> have to make this a Behavior (or Helper)? Is it even possible to do
> so, given the scenario I outlined?
>
> Sorry for confusing with the Excel-export idea, I was just suggesting
> that saying it sounded easier to me than writing this sort of code. I
> would like to do it in native CakePHP, if possible, especially since I
> am going to end up with several such tables soon. :)
>
> Thanks,
> SumanRS
>
> On Apr 29, 5:20 pm, "[EMAIL PROTECTED]" <[EMAIL PROTECTED]>
> wrote:
>
> > Hmm, I'm not sure updateAll will work in this case. It will work fine
> > if you want to update all rows with the same data but not otherwise.
> > If you want it to behave more like excel, where you can edit all
> > fields of all rows (or at least paginated rows) here's what I'd do:
>
> > 1) Select all rows in your controller
> > 2) In your view, inside a foreach($results as $result) loop generate a
> > new ajax form for each row in your results. with input fields for each
> > field in that particular row.
> > 3) here, you can do a couple things: 1) generate a separate ajax
> > button for each form that submits to an update function that saves
> > that particular row and refreshes the row's div. OR 2) to make it more
> > like excel, make the ajax button hidden (ie display none) and put in a
> > javascript function that submits the ajax button during the onChange
> > of each field in the row. sort of an "Autosave" feature.
>
> > OR
>
> > you could generate inputs for each field incremently named (ie
> > name="Model.1.someField", name="Model.1.anotherField" .... name
> > ="Model.2.someField", name="Model.2.anotherField" etc) and submit all
> > data with the same button and then in your controller go through your
> > data with a foreach loop and save each one ( foreach($this-
>
> > >data["Model"] as $model){$this->Model->save($model)} )
>
> > On Apr 29, 10:53 am, grigri <[EMAIL PROTECTED]> wrote:
>
> > > $this->YourModel->updateAll(array('new_field' => 'new_value'),
> > > array('1=1'));
>
> > > Note that you'll have to quote/escape the value yourself.
>
> > > On Apr 29, 4:27 pm,SumanRS<[EMAIL PROTECTED]> wrote:
>
> > > > Hi,
>
> > > > I've been using CakePHP for creating an online version of a listing
> > > > that has long been maintained using Excel. There are several hundred
> > > > rows in this table.
>
> > > > However, one thing where the Excel UI wins is in allowing a new field
> > > > (column) to be added. After that, it is easy to update the field for
> > > > all rows. If I wanted to do this in Cake, I would have to click "Edit"
> > > > on each row and edit the value for the field for each row.
>
> > > > One way I can think of solving this is:
> > > > 1. Export the CakePHP values to a CSV
> > > > 2. Edit the CSV in Excel
> > > > 3. Write PHP to open the edited CSV and update the fields (I've done
> > > > this before)
>
> > > > Is there a way to do this natively (and easily) in CakePHP?
>
> > > > Thanks,
> > > >SumanRS
>
>
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"CakePHP" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to