Should it then be:
$data = get_object_vars($master);

Instead of:
$data = get_object_vars($original);

> Read through the second and third lines slowly and carefully. Look at  
> each variable that is being set and each variable that is being read.  
> (Variables to the 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)){
> >       $data = get_object_vars($original);
> >           if ( is_array($data) )
> >               array_shift($data);
> >        $new = MyActiveRecord::Create('clones',$data);
> >        $new->save();
> >        if(false === $new->get_errors()){
> >                header('Content-type: text/html; charset=utf-8');
> >                //this is the part you need:
> >                print 'item_' .  $new->id;
> >        }else{
> >                header('HTTP/1.0 500 Server Error',true,500);
> >                exit;
> >        }
> > }else{
>
> >        header('HTTP/1.0 404 Missing',true,404);
>
> > }
>
> >> You're solving the wrong problem, then. Keep looking, it's right  
> >> there
> >> in front of you.
>
> >> Walter
>
> >> On Jul 1, 2009, at 1:36 PM, WLQ wrote:
>
> >>> I understand I should put this:
> >>> 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 what it IS
> >>>>> getting. What is the value of $data at that point? (Use echo(),
> >>>>> print_r(), something like that to output the value.)
>
> >>>>> I can see the error right away, looking back over the code. It's a
> >>>>> fairly stupid error on my part introduced while refactoring the
> >>>>> working code into an example you could pick apart and learn from.
>
> >>>>> I want you to find it, because otherwise you 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
> >>>>>>>>> thing you wish to be able to clone into the clones table.
> >>>>>>>>> MyActiveRecord creates a PHP class for each table you "wrap"  
> >>>>>>>>> it
> >>>>>>>>> around, and each row of the table becomes an object of that
> >>>>>>>>> class
> >>>>>>>>> when
> >>>>>>>>> you request it through MAR.
>
> >>>>>>>>> In short, this line:
>
> >>>>>>>>> if($master = MyActiveRecord::FindById('originals',$original)){
>
> >>>>>>>>> ...if it finds a table called 'originals' in your database,  
> >>>>>>>>> will
> >>>>>>>>> return the row with the ID matching $original (or false).
>
> >>>>>>>>> Walter
>
> >>>>>>>>> On Jun 29, 2009, at 12:25 PM, WLQ wrote:
>
> >>>>>>>>>> It says - Class originals does not exist
> >>>>>>>>>> Where does the originals class comes from? What is the
> >>>>>>>>>> originals
> >>>>>>>>>> from
> >>>>>>>>>> the code above?
>
> >>>>>>>>>>> If this is the code you are using (and I've added 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($original);
> >>>>>>>>>>>         array_shift($data); //get rid of the ID
> >>>>>>>>>>>         $new = MyActiveRecord::Create('clones',$data);
> >>>>>>>>>>>         $new->save();
> >>>>>>>>>>>         if(false === $new->get_errors()){
> >>>>>>>>>>>                 header('Content-type: text/html;
> >>>>>>>>>>> charset=utf-8');
> >>>>>>>>>>>                 //this is the part you need:
> >>>>>>>>>>>                 print 'item_' .  $new->id;
> >>>>>>>>>>>         }else{
> >>>>>>>>>>>                 header('HTTP/1.0 500 Server Error',true,
> >>>>>>>>>>> 500);
> >>>>>>>>>>>                 exit;
> >>>>>>>>>>>         }}else{
>
> >>>>>>>>>>>         header('HTTP/1.0 404 Missing',true,404);
>
> >>>>>>>>>>> }
>
> >>>>>>>>>>> Visit your test page with Firefox and with the Console tab  
> >>>>>>>>>>> of
> >>>>>>>>>>> Firebug
> >>>>>>>>>>> open. Make sure Firebug is set to show XHR transactions. You
> >>>>>>>>>>> should
> >>>>>>>>>>> be
> >>>>>>>>>>> able to observe the request to create_clone, and see the  
> >>>>>>>>>>> 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
> >>>>>>>>>>> script, 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 enabled error reporting on your server for your
> >>>>>>>>>>> test
> >>>>>>>>>>> pages,
> >>>>>>>>>>> so you can see 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
-~----------~----~----~----~------~----~------~--~---

Reply via email to