[SOLVED] How to create a page using API?

Talk about writing modules and plugins for CMS Made Simple, or about specific core functionality. This board is for PHP programmers that are contributing to CMSMS not for site developers
Locked
User avatar
Augustas
Forum Members
Forum Members
Posts: 241
Joined: Wed Oct 17, 2007 6:09 pm
Location: the world

[SOLVED] How to create a page using API?

Post by Augustas »

Hello,

maybe someone could share a code which creates a Page programmatically and assigns a template to it?

Thank you
Augustas
Last edited by Augustas on Sat Apr 11, 2015 8:59 am, edited 2 times in total.
Jos
Support Guru
Support Guru
Posts: 4017
Joined: Wed Sep 05, 2007 8:03 pm
Location: The Netherlands

Re: How to create a page using API?

Post by Jos »

I saw this topic. http://forum.cmsmadesimple.org/viewtopi ... =6&t=71835
Maybe it helps a bit.
User avatar
Augustas
Forum Members
Forum Members
Posts: 241
Joined: Wed Oct 17, 2007 6:09 pm
Location: the world

Re: How to create a page using API?

Post by Augustas »

Jos wrote:I saw this topic. http://forum.cmsmadesimple.org/viewtopi ... =6&t=71835
Maybe it helps a bit.
Thank you Jos for the effort, I saw this topic, but it has no information I need.
calguy1000 just mentions that
"There is lots of documentation in the API docs"
and
"Creating content pages is a bit more complicated, but not by much."
and then he gives some hints for CMSMS 2.0 users, while I am working with 1.11.X
calguy1000
Support Guru
Support Guru
Posts: 8169
Joined: Tue Oct 19, 2004 6:44 pm
Location: Fernie British Columbia, Canada

Re: How to create a page using API?

Post by calguy1000 »

This is 2.0 code. The 1.x code is similar (there is no concept of a design).

$contentobj = new Content;
$contentobj->SetName('Test Page');
$contentobj->SetAlias();
$contentobj->SetMenuText('Test Page');
$contentobj->SetPropertyValue('searchable',1);
$contentobj->SetPropertyValue('design_id',$design_id);
$contentobj->SetTemplateId($template_id);
$contentobj->SetOwner(1);
$contentobj->SetParentId(-1);
$contentobj->SetActive(TRUE);
$contentobj->SetShowInMenu(TRUE);
$contentobj->SetCachable(TRUE);
$contentobj->SetPropertyValue('content_en',$some_html);
$contentobj->Save();

You will need to update the hierarchy positions after creating a new page programattically. but that is a simple method in the contentoperations class
Follow me on twitter
Please post system information from "Extensions >> System Information" (there is a bbcode option) on all posts asking for assistance.
--------------------
If you can't bother explaining your problem well, you shouldn't expect much in the way of assistance.
User avatar
Augustas
Forum Members
Forum Members
Posts: 241
Joined: Wed Oct 17, 2007 6:09 pm
Location: the world

Re: How to create a page using API?

Post by Augustas »

That's useful, thank you.
Locked

Return to “Developers Discussion”