Question

I am trying to add page via code in Concrete5(CMS).

$parentPage           = Page::getByPath("/hotel");
$ct                   = CollectionType::getByHandle("products");
$data                 = array();
$data['cName']        = 'New Page';
$data['cDescription'] = 'Description here';
$newPage              = $parentPage->add($ct, $data);

But I get MySql error:

mysql error: [1064: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'LIMIT 1' at line 1] in EXECUTE("select max(cDisplayOrder) from Pages where cParentID = LIMIT 1")

And also How can I add an Attribute when created page??

Was it helpful?

Solution

The SQL error implies to me that the $parentPage wasn't instantiated properly. C5 is confusing in that the Page::getBy...() and a few others will return an object even if the page doesn't exist -- it's your responsibility to check it for errors.

Are you expecting that /hotel exists? You have to create it first. You should var_dump($parentPage) after you've loaded it.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top