Moving a page into a sub folder
I've built a site using standard Perch and all is working marvellously.
However, I came across a situation that could get a bit sticky in future where an end user created a page in the root of the site and subsequently decided they would like a subpages of this page.
The page was called
sub-page.php in the root.
They opened the Page Options, and changed the Path to be
/sub-page/index.php, checked the "Move the page to this location" checkbox entered a Subpage folder of
/sub-page/ and saved.
The errors generated were as follows:
Warning: include(perch/templates/pages/GHT_Main_Master.php): failed to open stream: No such file or directory in /var/sites/g/ghtraining.co.uk/public_html/sub-page/index.php on line 1 Warning: include(perch/templates/pages/GHT_Main_Master.php): failed to open stream: No such file or directory in /var/sites/g/ghtraining.co.uk/public_html/sub-page/index.php on line 1 Warning: include(): Failed opening 'perch/templates/pages/GHT_Main_Master.php' for inclusion (include_path='.:/usr/newage/lib/php') in /var/sites/g/ghtraining.co.uk/public_html/sub-page/index.php on line 1
This seems to be because the path to the template is now incorrect and it cannot be found.
The solution was for me to edit the
<?php include(str_replace('/', DIRECTORY_SEPARATOR, 'perch/templates/pages/GHT_Main_Master.php')); ?>
and change it to
<?php include(str_replace('/', DIRECTORY_SEPARATOR, '../perch/templates/pages/GHT_Main_Master.php')); ?>
Is there a way to resolve this automatically or prevent it (other than ensuring the page is not moved!) or am I doing something wrong? I suppose habitually creating pages as if they may contain subpages would prevent this problem.
Diagnostics below (just in case)
Perch: 2.8.15, PHP: 5.4.42, MySQL: mysqlnd 5.0.10 - 20111026 - $Id: c85105d7c6f7d70d609bb4c000257868a40840ab $, with PDO Server OS: Linux, cgi-fcgi Installed apps: content (2.8.15), assets (2.8.15), categories (2.8.15), perch_blog (5.0), perch_forms (1.8.3), perch_mailchimp (2.0.1), perch_members (1.3), perch_twitter (3.5.1) App runtimes: <?php $apps_list = array( 'content', 'categories', 'perch_forms', 'perch_members', 'perch_blog', 'perch_twitter', 'perch_mailchimp' ); PERCH_LOGINPATH: /perch PERCH_PATH: /var/sites/g/ghtraining.co.uk/public_html/perch PERCH_CORE: /var/sites/g/ghtraining.co.uk/public_html/perch/core PERCH_RESFILEPATH: /var/sites/g/ghtraining.co.uk/public_html/perch/resources Image manipulation: GD PHP limits: Max upload 100M, Max POST 100M, Memory: 128M, Total max file upload: 100M Resource folder writeable: Yes DOCUMENT_ROOT: /var/sites/w/www.ghtraining.co.uk.gridhosted.co.uk/public_html HTTP_HOST: www.ghtraining.co.uk.gridhosted.co.uk REQUEST_URI: /perch/core/settings/diagnostics/ SCRIPT_NAME: /perch/core/settings/diagnostics/index.php