Jump to content

Recommended Posts

Posted

Hi, I just started using processwire this week and I have some troubles with the api's.

I'm trying to create multiple parent->children pages but it gets stuck at the 2nd child;

I want to create those pages with the api's: 

Category

--Subcategory

----Sub-Subcategory

--------Some page

--------Another page

Here is a small part of code that I made to test and It doesn't seem to be possible right now, or am I doing something wrong ?

$pgs = array("1","2","3","4","5");

foreach ($pgs as $key => $value) {
	if ($value == "1") {
		$parent = "/";
	}else{
		$v = $value - 1;
		$parent = "/test$v/";
	}
	
	$p = new Page();
	$p->of(false);
	$p->template = "basic-page";
	$p->parent =  wire("pages")->get("$parent");
	$p->title  = "test".$value;
	$p->save();
}

Basically this should create 5 pages, with each page to be the child of the previous one. It gets stuck at the test2 page, for page3 it says 

Fatal error: Exception: Can't save page 0: /test3/: It has no parent assigned 

I think pages are not available right after they are created from api ? Is there any method to do this with processwire right now ?

Thanks !

//Edit:

I even tried this code to take out any possible issue with the code

$p = new Page();
$p->of(false);
$p->template = "basic-page";
$p->parent =  wire("pages")->get("/");
$p->title  = "test1";
$p->save();

$p = new Page();
$p->of(false);
$p->template = "basic-page";
$p->parent =  wire("pages")->get("/test1/");
$p->title  = "test2";
$p->save();

$p = new Page();
$p->of(false);
$p->template = "basic-page";
$p->parent =  wire("pages")->get("/test2/");
$p->title  = "test3";
$p->save();

$p = new Page();
$p->of(false);
$p->template = "basic-page";
$p->parent =  wire("pages")->get("/test3/");
$p->title  = "test4";
$p->save();

So the pages are not available to the api after creating them ? How to get arround this ?

Posted

I dont get the logic here.

Shouldnt parent be /test1/test2/ ?

Parent /test2/ doesnt exist.

Posted

Oh now I see where the issue was. Thanks for pointing it out. Sorry for asking so stupid question, i'm still learning how processwire works  :rolleyes:

Posted

Thanks! It's a pleasure to work PW once you understand you are not forced to do things 'the CMS way'. Seems like this is the hardest part when coming from another cms.

  • Like 1
Posted

It's a pleasure to work PW once you understand you are not forced to do things 'the CMS way'.

Seems like this is the hardest part when coming from another cms.

Very well pointed. At first pw use, this can hold newbies, starters and designers in a corner.

Everything in pw is "a page" and when you "see it" - it feels just like it should.

Your phrase is very functional for in the newbie section.

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...