valan Posted January 3, 2014 Share Posted January 3, 2014 Recently I've discovered unexpected (for me) behavior of Page children property. My scrip creates several pages - $mypage and its few child pages. Within the same script this code "$mypage->children" returns empty PageArray, while this code "$pages->get($mypage->id)->children" returns expected children PageArray. Is there any way to stay with "$mypage->children" syntax? E.g. may be I miss some step during Page creation that properly initializes this property? Link to comment Share on other sites More sharing options...
*Most Powerful Pony!* Posted January 3, 2014 Share Posted January 3, 2014 А можешь подробнее описать, что именно не так, по твоему? Просто не очень понимаю откуда именно у тебя берется $mypage, просто мне когда нужна специфичная страница, изначально всегда её объявляю в шапке ( $homepage = $pages->get('/') ) и дальше использую. Все объекты с данным классом и все их методы отрабатывают как положено, не смотря на контекст, даже есть пример с рекурсией в файлах страницы через которые можно получить страницы на которых они объявлены, что бы вновь получить список файлов. Link to comment Share on other sites More sharing options...
Soma Posted January 3, 2014 Share Posted January 3, 2014 Please keep english here. 1 Link to comment Share on other sites More sharing options...
valan Posted January 3, 2014 Author Share Posted January 3, 2014 MPP, thanks for reply! $mypage it is not PW api variable . It is created in the php script as below: $mypage = new Page(); $mypage->template = 'mytemplate'; $mypage->parent = 'path-to-mypage'; $mypage->name = uniqid(); $mypage->of(false); $mypage->myproperty = $somevalue; $mypage->save(); $mypage->of(true); Its child Pages are created in the same way after $mypage. Problem in brief: in the same script $mypage->children doesn't work (returns empty PageArray), while $pages->get($mypage->id)->children works (returns non-empty PageArray with all newly created children Pages). Link to comment Share on other sites More sharing options...
Soma Posted January 3, 2014 Share Posted January 3, 2014 Maybe you can also let us know what PW version, and where this script is run: Template, Module, Bootstrap ... This works as expected for me. Though possible there was some fix. I could image the problem has to do with pages in cache/memory vs pages queried from DB. Once you create a new page and add children to it, the $mypage page is already in memory and $mypage->children() may not return any children cause there was none when you created the page. Though it works for me so looks like children() makes a DB query after all. BTW you don't need $page->of(false), because a newly created page via API has no output formatting yet. Link to comment Share on other sites More sharing options...
valan Posted January 3, 2014 Author Share Posted January 3, 2014 PW 2.3.1 PHP 5.3.x, script runs in template. I'll upgrade to the latest dev next week and check if problem still there. Thanks for tip with of(false). Link to comment Share on other sites More sharing options...
*Most Powerful Pony!* Posted January 4, 2014 Share Posted January 4, 2014 How it you declare children? You just save them with the current parent? And then we go to the parent, I understand you correctly? I think if you add them through ->add everything else, should work correctly Link to comment Share on other sites More sharing options...
valan Posted January 4, 2014 Author Share Posted January 4, 2014 MPP, thanks! Will check if after "->add" it works. Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now