Can't create page programmatically with custom page type
Permalink
Hi all
I'm trying to create pages from a Dashboard editing interface using the pagetype 'job', but although the pages are being created, they aren't using the pagetype's template file (job.php). They're showing the header and footer of the site, but nothing else - I don't understand where the system is getting the layout from. I've cleared (and disabled) the cache.
Anyway, here's my controller.php for the dashboard single page:
and here's my job.php pagetype file:
(you can see it's just slightly altered version of full.php.
What I see is the attached file. You can see the words 'Job description' are not being pulled from my pagetype php file.
Does anyone have any ideas? It doesn't seem to affect the core full.php pagetype, but that's no use to me - I have to be able to use a custom one.
Any help would be much appreciated :)
I'm trying to create pages from a Dashboard editing interface using the pagetype 'job', but although the pages are being created, they aren't using the pagetype's template file (job.php). They're showing the header and footer of the site, but nothing else - I don't understand where the system is getting the layout from. I've cleared (and disabled) the cache.
Anyway, here's my controller.php for the dashboard single page:
<?php defined('C5_EXECUTE') or die(_("Access Denied.")); class DashboardJobsController extends Controller { public $helpers = array('html','form'); public function on_start() { Loader::model('page_list'); $this->error = Loader::helper('validation/error'); } public function view() { } public function add() { if($this->isPost()){ Loader::model('collection_types'); $path = "/test"; $newPage = Page::getByPath($path);
Viewing 15 lines of 34 lines. View entire code block.
and here's my job.php pagetype file:
<?php defined('C5_EXECUTE') or die("Access Denied."); $this->inc('elements/header.php'); ?> <div id="central" class="no-sidebar"> <div id="body"> Job description:<br /> <?php $a = new Area('Main'); $a->display($c); ?> </div> <div class="spacer"> </div> </div> <?php $this->inc('elements/footer.php'); ?>
(you can see it's just slightly altered version of full.php.
What I see is the attached file. You can see the words 'Job description' are not being pulled from my pagetype php file.
Does anyone have any ideas? It doesn't seem to affect the core full.php pagetype, but that's no use to me - I have to be able to use a custom one.
Any help would be much appreciated :)
Hi jordan
I have, it's the add() and savedata() functions:
I'm using the code from Andrew's Single Page editing interface HOWTO, stripping it to its basics so I understand how everything works before adding in new features.
The page type is definitely activated - I can choose it in the Design interface when I edit the page manually. Even when I change back to the full_width pagetype, it shows up like before. Something very weird is happening!
I have, it's the add() and savedata() functions:
public function add() { if($this->isPost()){ Loader::model('collection_types'); $path = "/test"; $newPage = Page::getByPath($path); $data = array(); $data['cName'] = $this->post('pageName'); $data['cDescription'] = $this->post('pageDesc'); $ct = CollectionType::getByHandle('job'); $p = $newPage->add($ct, $data); $this->saveData($p); $this->set('message', t('Page added.')); $this->view(); } }
Viewing 15 lines of 20 lines. View entire code block.
I'm using the code from Andrew's Single Page editing interface HOWTO, stripping it to its basics so I understand how everything works before adding in new features.
The page type is definitely activated - I can choose it in the Design interface when I edit the page manually. Even when I change back to the full_width pagetype, it shows up like before. Something very weird is happening!
Oh, sorry about that -- missed the code the first time.
Hmm... not really sure, it looks like you're doing everything right. What if you remove the leading "c" from the array keys for $data (so it's $data['name'] and $data['description'])? Not sure why that would cause the problem you're having, but I'm looking at some code of mine that does work to add new pages and my array keys don't have the leading "c" in them, so worth a shot I guess.
Also, not sure if you need that $this->saveData($p) call (and also, what's the $this->view() for?) -- again, not sure why those would have any effect, but worth a shot.
Sorry I don't know too much about the details here -- just some random guesses.
EDIT: Ugh, missed the "view all code" thing in your sample. I see what that function is doing now. Another random guess is you might try putting an ampersand before the $p in your saveData function definition, so:
function saveData(&$p) {
Good luck.
Hmm... not really sure, it looks like you're doing everything right. What if you remove the leading "c" from the array keys for $data (so it's $data['name'] and $data['description'])? Not sure why that would cause the problem you're having, but I'm looking at some code of mine that does work to add new pages and my array keys don't have the leading "c" in them, so worth a shot I guess.
Also, not sure if you need that $this->saveData($p) call (and also, what's the $this->view() for?) -- again, not sure why those would have any effect, but worth a shot.
Sorry I don't know too much about the details here -- just some random guesses.
EDIT: Ugh, missed the "view all code" thing in your sample. I see what that function is doing now. Another random guess is you might try putting an ampersand before the $p in your saveData function definition, so:
function saveData(&$p) {
Good luck.
Can you post a screenshot of your active theme's directory, including all the files in it? Job.php should be in it. I'm concerned it's not, and default.php is being inherited instead.
Hi Andrew, thanks for replying..
For some bizarre reason, and after leaving it for a day, it seems to be working as expected now o.O
all's well that ends well I suppose! :)
For some bizarre reason, and after leaving it for a day, it seems to be working as expected now o.O
all's well that ends well I suppose! :)
Off the top of my head, I'm wondering if you ever installed the new page type? Also, is the theme that your new page type template lives in activated (the default) for your site?