Programatically updating a page path (cHandle) requires rescanCollectionPath()

Permalink 6 users found helpful
I found out after many hours of bashing away that to update a page path using $page->update() a rescanCollectionPath() is required.

I didn't see any mention of rescanCollectionPath() here in the forums. So I hope this post helps someone in the future.
Here is an example:
$pagebycID = Page::getByID('113');
   $new_data = array();
   $new_data['cHandle'] = 'new-path';
   $new_data['cName'] = 'new-title';
   $pagebycID->update($new_data);
   $pagebycID->rescanCollectionPath();


Also thanks to jshannon and digia3 on IRC for their help.

mrowell
 
A3020 replied on at Permalink Reply
A3020
Cool, I had the same problem. Thanks for sharing.
Remo replied on at Permalink Reply
Remo
I guess we all have the same problemhttp://www.concrete5recipes.com/tricks/update-page-path-programmati... ;-)

Took me a minute to figure this out too..
Kiesel replied on at Permalink Reply
That was driving me insane. Checked my code a few times, thought I'll see soon some pinky elephants flying by. You saved my day! Thanks!
SeanDevoy replied on at Permalink Reply
Still a great POST even years later. Especially since the example of $some_page>add() with a "cHandle"=>"my_handle" does not use that handle as the page path (as documented).

I wasted more than a day trying to fix this problem.
THANK YOU!