[Fixed] Single Page from package not working

Permalink
Trying to add a Single Page to my package, but it is not found by Concrete5 (with latest version: 5.7.5.9).

I just want a simple Single Page without controller (for now), and located in my package. So I added a file in packages/my_package/single_pages/sptest.php which only contains some HTML text to see if it works.

Then I added this code in my package controller:
SinglePage::add('/sptest', $pkg);
(As explained here:http://documentation.concrete5.org/developers/working-with-pages/si... )

Then I went to the page "Single Pages" in Concrete5 Dashboard, and just typed "sptest" in the form after my site's URL, and clicked "Add".

But I get the error: That specified path doesn't appear to be a valid static page.

Did I miss something ?

 
hutman replied on at Permalink Reply
hutman
When you add a Single Page through a Package controller, it should install when you either Install or Upgrade the package, you should not have to manually add it to the Single Pages list, did you install/upgrade the package after adding that code?

You also have to have the correct namespacing inside of the Single Page, so make sure that the top of your Single Page has this code too

<?php
namespace Concrete\Package\MyPackage\SinglePages;
defined('C5_EXECUTE') or die('Access denied.');


Of course replacing MyPackage with the correctly camelcased package name.
jlgrall replied on at Permalink Reply
Ok, thanks, so I actually have to uninstall and then re-install my package to make it work.

It does work, but it makes me lose parts of my package configuration in the process of uninstalling, which is very annoying.

Instead, here is a quick hack I made so that I can add a Single Page from my package without having to re-install the whole package. I temporarily add the following code to my package controller, in the method "getPackageName()":
$pkg = $this;
SinglePage::add('/sptest', $pkg);

And then I go to a page that displays my package's name in concrete5 Dashboard (like the Details page of my package). The Single Page is now added and I can remove the temporary code.
hutman replied on at Permalink Best Answer Reply
hutman
You don't actually have to uninstall and reinstall, you just have to increment your version number and put your new code so that it gets called by the upgrade method.
jlgrall replied on at Permalink Reply
Nice, it works. Thank you.