Unfortunately it's not them who create a problem.
THis is the code I use:
$original = $_POST['original'];
if($master = MyActiveRecord::FindById('widgets',$original)){
$data = get_object_vars($master);
array_shift($data);
$new = MyActiveRecord::Create('clones',$data);
$new->save();
if(false === $new->get_errors()){
header('Content-type: text/html; charset=utf-8');
print 'item_' . $new->id;
}else{
header('HTTP/1.0 500 Server Error',true,500);
exit;
}
}else{
header('HTTP/1.0 404 Missing',true,404);
}
> Those errors wont occur when you remove the "echo" / "print_r" statements
> ... they are just moaning about the web server detecting content and
> expressing its own headers...
>
> If you remove the lines i asked u to add it will be fine
>
> Alex
>
> ----- Original Message -----
> From: "WLQ" <[email protected]>
> To: "Prototype & script.aculo.us" <[email protected]>
> Sent: Friday, July 03, 2009 1:53 PM
> Subject: [Proto-Scripty] Re: MySQL - order
>
>
> Well
> widgets Object ( [id] => 3 [name] => 3.00 [description] => 3
> > [position] => 3 [updated_at] => 2009-06-05 14:39:07 )
>
> > And the second one ($original) returned an id of 3. So the answer is
> > you should write $master instead of $original.
>
> > So this problem is solved, but the errors won't stop. You solve one
> > problem and here you go another one:
> > Cannot modify header information - headers already sent by (output
> > started at:1) LOCATION: line 8
>
> >> If anything it should be $master as thats what is most likely to be an
> >> array.... I dont know MAR at all but unless it parses the I do into a
> >> loop
> >> then t is inal is moe likt into be an id/string/int thaMAR array...
>
> >> To test
>
> > er............ {
>
ray.> p
>t_r($master); // shto d return .. {
>
>
> >> eay
an array or
> >> object)
>
> >> ----- Original Message -----
> >> From:/ shQ" <[email protected]>
> (noTo: "Prototype & script.aculo.us"
> >> <[email protected]>
> >> Sent: Friday, July 03, 2009 12:51 PM
> >> Subject: [Proto-Scripty] Re: MySQL - order ID
> > orde
> > ID
>
> > d it then be:
> >> $data = get_object_vars($master);
>
> >> Instead of:
> >> $data = get_object_var ordei ID
>
> >>be:
>a>> $datgh the s the and third line;
> owly and carefully. Look at
> >> > each variable that is being set and each variable that is being read.
> >> > (Variables ly. Le left of the = are being set.) Ask yourself what it's
> >> > supposed to be carrying, and see if you can spot what it really is
> >> > instead.
>
> >> > Here's a hint: In line two, I assigned a value to a variable, but on
> >> > line 3, I forgot to use it and used something else instead.
>
> >> > Walter
>
> >> > On Jul 2, 2009, at 6:09 AM, WLQ wrote:
>
> >> > > This is as far as I've been able to go, please tell what's wrong.
>
> >> > > $original = $_POST['original'];
> >> > > if($master = MyActiveRecord::FindById('widgets',$original)){
> >> > > $dat> $data = get__vject_varginal);
> >> > > if ( is_array($data) )
> >> > > array_shift($data);
> >> > > $new = MyA> > $data = gereobject_vnes',>> > > if ( is
>rray($da$new->save();
== $ntw->gors()){
> >> > > header('ContA> > ydata = g/html; charset=utf-8');
> >> > > //tve();
> >> > > ift you need:
> >> > > print 'rirs('i.em_ew->id header('C
ntense{
> >> > > he> >r('HTTP/1.0 500 Server Error',true,50 >>
> >> ft eu ne
> >> > > }
> > print itese{
>
> >> > > header(}else{
. >>04 Missing',true,41.0;
>
> >> > > ror
>
ht
> >> > >> there
> >> > >> in fro> of you.
>
> >> > >> Walter
>
> >> > >> On Jul 1, 2009, at 1:36 PM, WLQ wrote:
>
> >> > >>> I understand I should plem, is:
> >> > >>> if(is_array($data)) {
> >> > >>> array_shift($data);
> >> > >>> }
>
> >> > >>> Instead of:
> >> > >>> array_shift($data);
>
> >> > >>>> Or just do ....
>
> >> > >>>> if(is_array($data)) {
> >> > >>>> array_shift($data);
>
> >> > >>>> }
>
> >> > >>>> HTH Alex
>
> >> > >>>> ----- Original Message -----
> >> > >>>> From: "Walter Lee Davis" <[email protected]>
> >> > >>>> To: <[email protected]>
> >> > >>>> Sent: Wednesday, July 01, 2009 5:56 PM
> >> > >>>> Subject: [Proto-Scripty] Re: MySQL - order ID
>
> >> > >>>>> Which means it's not getting an array. So look and see whate whaS
> > it IS
> >>>> getting. What is the value of $data at that point? (Use echo(),
> >> > >>>>> print_r(), see that it ke that to output the value.)
>
> >> > >>>>> I can see the error right away, looking back over thhat ie the va
> >> > >>>>> a
> >>s >>>>> fairly stupid error on my part introduced while refactoring the
> >he va>ue.)working code into an example you could pick apart and learn from.
>
> >> > >>>>> I want you to find it, because otherwisidyou will never stand on
> >> > >>>>> your
> >> > >>>>> own here.
>
> >> > >>>>> Walter
>
> >> > >>>>> On Jul 1, 2009, at 10:31 AM, WLQ wrote:
>
> >> > >>>>>> But here's what I get in error:
> >> > >>>>>> array_shift() [function.array-shift]: The argument should be an
> >> > >>>>>> array
>
> >> > >>>>>> On this line:
> >> > >>>>>> array_shift($data);
>
> >> > >>>>>>> Yes. Like any example that you will ever find on the Web, this
> >> > >>>>>>> one
> >> > >>>>>>> needs to be adjusted to match your environment. Some basic
> >> > >>>>>>> fluency in
> >> > >>>>>>> PHP is a requirement to use the MAR system, it can't divine
> >> > >>>>>>> everything
> >> > >>>>>>> for you.
>
> >> > >>>>>>> Walter
>
> >> > >>>>>>> On Jul 1, 2009, at 5:57 AM, WLQ wrote:
>
> >> > >>>>>>>> Right, shouldn't then that be 'widgets'? Because the table of
> >> > >>>>>>>> our
> >> > >>>>>>>> original sortable list were controlled by the widgets table.
> >> > >>>>>>>> So
> >> > >>>>>>>> like:
> >> > >>>>>>>> if($master = MyActiveRecord::FindById('widgets',$original)){
>
> >> > >>>>>>>>> Originals is a table in the database, it contains one of each
> >> > >>>>>>>>> type of
> > pe of
> >> > >>>> >>> thinu wish to be able to clone into the clones table.
> >> > >>>>>>>>> MyActiveRecord type of
> >> > >cl>>>>>> teach table you "wrap"
> >> > >>>>>>>>> it
> >> > >>>>>>>>> around, and each row ofsh to be able om clone iject of that
> > hat
> >> > >>>>>>class
> >> > >>>>>>>>> when
> >> > >>>>>>>>> you request it through MAR.
>
> >> > >>>>>>>>> In shf that
a>> > >>>:
>
> >> > >f the>>> if($master =
> >> > >>>>>>>>> MyActiveRecord::FindById('origina>>>>>>>>> when){
>
> >> > >>>>>>>>> ...if it finds a table called 'originals' in inr database,
> >> > >>>>>>>>> will
> >> > >>>>>>>>> ret return the rothwith thematching $original (or false).
>
> >> > >>>>>>>>> Walter
>
> >> > >>>>>>>>> On Ju>>>>> return t 1 row wit WLQ wrote:
>
> > >> >>>>>>>>>> It says - Class originals does not exist
> >> > >>>>>>>>>> iginal (or fal o).
>
> class comes from? What is the
> >> > > >>>>>>>> originals
> >> > >>>>>>>>>> from
> >> > >>>>>>>>>> the code above?
>
> >> > >>>>>>>>>>> If this is > code you arhere doe( the originded the
> >> > >>>>>>>>>>> missing
> >> > >>>>>>>>>>> close
> >> > >>>>>>>>>>>>parenthesis), then the fact that you are getting a 200 back
> >> > >>>>>>>>>>> (and a
> >> > >>>>>>>>>>> new
> >> > >>>>>>>>>>> ID) means that you have successfully created a new clone.
> >> > >>>>>>>>>>> Otherwise,
> >> > >>>>>>>>>>> you should be getting a 500 or 404 back.
>
> >> > >>>>>>>>>>> //create_clone.php
> >> > >>>>>>>>>>> $original = $_POST['original'];
> >> > >>>>>>>>>>> if($master = MyActiveRecord::FindById('originals',
> >> > >>>>>>>>>>> $original)){
> >> > >>>>>>>>>>> $data = get_object_vars($rs(ginal);
> >> > >>>>>>>>>>> array_shift($data); //get rid of the ID
> >> > >>>>>>>>>>> >>> $new = MyAeRiveRecctreate('clones',$data);
> >> > >>>>>>>>>>> $new->save();
> >> > >>>>>>>>>>> if(false>>>>>>>> $new _eMyActiveay_
>> > >>>>>>>>>>> header('Content-type: text/html;
> >> > >>>>>>>>>>> charset=utt=utfones',$data);
>>> > >>>
//this is the part you need:
> >> > >>>>>>>>>>> print 'item_' . $new->id;
> >> > >>>harset=utheade8'){
> >> >>>>>>>>>>> header('HTTP/1.0 500 Server Error',true,
> >> > >>>>>>>>>>>>> 50;
> > );
he part you need:
exit;
> >> > >>>>>>>>>>> }}else{
>
> >> > >>>>>>>>>>> header('HTTP/1.0 404 Missing'>>>>>>>0> er('HTTP/
>
> >> > >>>>>>>>>>> }
>
with the Console tab
> >> > >>>>>>>>>>> of
> >> exit;>> >> > Firebug
> >> > >>>>>>>>>>> open. Make sure Firebug is set to show XHR transactions.
> >> > >>>>>>>>>>> You
>
> > >ith th>>>> should
> >> > >>>>>>>>>>> be
> >> > >>>>>>>>>>> able to observe the request to create_clone, a>> ablethe
> >> > >>>>>>>>>>> reply
> >> > >>>>>>>>>>> from
> >> >>>>>>>>>>>>> the server. The reply should be the new ID of your clone.
> >> >>>>>>>>>>>>> If
> >> > >>>>>>>>>>> it
> >> > >>>>>>>>>>> isn't,
> >> > >>>>>>>>>>> then you have more debugging to do.
>
> >> > >>>>>>>>>>> Things to check here:
>
> >> > >>>>>>>>>>> * Have you included/required the library (MyActiveRecord)
> >> > >>>>>>>>>>> in
> >> > >>>>>>>>>>> this
> >> > >>>>>> > >>>>cript, and have you defined the constants it needs (MySQL
> >> > >>>>>>>>>>> address
> >> > >>>>>>>>>>> and
> >> > >>>>>>>>>>> credentials, also known as a DSN).
> >> > >>>>>>>>>>> * Have you got a MySQL table called clones?
> >> >> * Have you g Have you enabled error reporting on your >>>>>> * Have r
> >> > >>>>>>>>>>> test
> >> > >>>>>>>>>>> pages,
> >> > >>>>>>>>>>> a MySQL tablee the PHP errors as they whiz by?
> >> > >>>>>>>>>>> * Have you ordered that fat book I recommended?
>
> >> > >>>>>>>>>>> Debugging PHP is like playing Whack-a-Mole. You fix one
> >> > >>>>>>>>>>> thing,
> >> > >>>>>>>>>>> and
> >> > >>>>>>>>>>> another pops up. You iterate, in other, more dainty words.
>
> >> > >>>>>>>>>>> Walter
>
> >> > >>>>>>>>>>> On Jun 28, 2009, at 12:04 PM, WLQ wrote:
>
> >> > >>>>>>>>>>>> Also I've used that clone.php you gave, the only thing it
> >> > >>>>>>>>>>>> doesn't do
> >> > >>>>>>>>>>>> is change the MySQL table itself.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Prototype & script.aculo.us" 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/prototype-scriptaculous?hl=en
-~----------~----~----~----~------~----~------~--~---