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