Crete page button in dashboard Code

Permalink 2 users found helpful
Hi Team

I would like some help, I am building a add-on with a dashboard page.

Now what I need to do is have the user select a page to link to.. No problem all done, What I would also like is a button above that to create a page.With a fixed page type and location with a popup box like the sub page button does in edit mode. Which you have to fill out the pages set attributes?
i have

<?php function AddingDomainPage()  
   { 
   $pData = array('uID' => 12, 'pkgID' => 0, 'cName' => 'Test Five Page', 'cHandle' => 'testfive', 'cDatePublic' => '2011-03-01');
$oPage = Page::getByPath('/more-domains');
$ct = CollectionType::getByHandle('DomainPage');
$newPage = $oPage->add($ct, $pData); 
}
?>
&
<div class="CreatePage">
   Create A domain Page  .<input type="button" value="CreatePage" onclick="AddingDomainPage()" /><br/>
   <div class="clearfix">



But does not work I guess i need to load some helpers also?
Any Advise would be nice Thanks

Carl

carl101lee
 
JohntheFish replied on at Permalink Reply
JohntheFish
I think hereNT's page manager addon (just released) does that.

http://www.concrete5.org/about/blog/add-on-releases/add-on-approved...
carl101lee replied on at Permalink Reply
carl101lee
Hi John

Thanks to your response, But this add-on is a bit to over the top and for what I need.

I don't so much need to manage the page its self ummmm. this would be helpful I guess once for management after they are added.

I have an add-on already purchased from the market place which manages muti-domains on 1 concrete 5 install. Now in the manage page in the dashboard, I have modified the edit and view to include a create page button, I just need to know what the code is I need this button to run, also I am guessing in order to use the some pop- ups as the add sub-page it would be ideal to load a some of the assets of library to help?

So I guess what I need is the code and dependences for creating the page. Also would be very useful now i think about it to have in the edit options a way to see the linked page details also... ( ill work on that next).

I did ask the mod designer but this is an extra feature I want which he does not support as part of the add-on.

Thanks for any help
Carl
JohntheFish replied on at Permalink Reply
JohntheFish
To create a page:

$page = Page::add(CollectionType $pageType, $data);
$page->addBlock(BlockType $bt, Area $a, $data);


from
http://www.concrete5.org/documentation/developers/pages/overview...
There are more details about the parameters on the docs page.
JohntheFish replied on at Permalink Reply
JohntheFish
You could also probably dig out big chunks of useful code from Composer.
carl101lee replied on at Permalink Reply
carl101lee
Hi Their

Thanks for the help, I got it all working with the below code, no problems. Just one more question, I have assigned extra page properties as default to a pages types, so that when created it has the boxes added.

I am a little confused how to assign my form inputs to these fields on creation also? as "akID[2]" comes up as their ids but I cant use this code to set the on creation? I guess these attributes are a little more complex to assign.

I have created a Domain_Price attribute for each page how do I set this on creation based on a form field any ideas?

Basic code to create a page using a form.

add_page_form.php
<?php  defined('C5_EXECUTE') or die(_("Access Denied."));
Loader::model('mapping', 'multiple_domains');
$form = Loader::helper("form");
$ps = Loader::helper('form/page_selector');
$ih = Loader::helper("concrete/interface");
//<!-- carl -->
$pagename = "";
if(isset($_POST['submitpage'])) {
Create_me_a_page();
}
function Create_me_a_page() {
    if (empty($_POST["pagename"])) {
echo "<div class='alert alert-error'>please enter a page name to corrispond with the domain</div>";
       } else {
$parentPage = Page::getByPath("/domain-names");


include code
<?php  Loader::packageElement("dashboard/add_page_form", "multiple_domains" ) ?>


Thanks for any help