oap Posted August 18, 2015 Share Posted August 18, 2015 In my home.php (a template, as you'd expect for the homepage) then I take a look at the URL segments. I want to provide some shortlinks, e.g. example.com/php redirects to example.com/languages/php/. That all works. But if I want to display a 404, by using "throw new PageNotFoundException();" then things go pearshaped: Fatal error: Cannot redeclare renderNav() (previously declared in /var/www/pw/public_html/site/templates/_init.php:20) in /var/www/pw/public_html/site/templates/_init.php on line 20 I'm not sure how to get around this? (or exactly why it's coming up) This is the case if I try to declare a 404 at the top of any template. Link to comment Share on other sites More sharing options...
LostKobrakai Posted August 18, 2015 Share Posted August 18, 2015 I'm not sure, where you got that exception, but normally pw uses Wire404Exception() to throw 404 errors. Link to comment Share on other sites More sharing options...
oap Posted August 18, 2015 Author Share Posted August 18, 2015 I'm not sure, where you got that exception, but normally pw uses Wire404Exception() to throw 404 errors. Thanks for pointing that out, I think I took it from this forum page but didn't fully read the later posts! But unfortunately Wire404Exception() produces the same problem. Link to comment Share on other sites More sharing options...
louisstephens Posted August 21, 2015 Share Posted August 21, 2015 (edited) So I am using a blank template for a page (which is only calling the title of the page). It is also not including the header or footer in the template. I am then calling the page in my basic template using: <?php echo $page->import_page->render(); ?> However, when I go to refresh the page again, I get an error: "Compile Error: Cannot redeclare renderNav() (previously declared in /Applications/MAMP/htdocs/ProcessWire/site/templates/_init.php:20) (line 49 of /Applications/MAMP/htdocs/ProcessWire/site/templates/_init.php) Has anyone had the same issues? Edited August 21, 2015 by LostKobrakai Merged into earlier topic Link to comment Share on other sites More sharing options...
LostKobrakai Posted August 21, 2015 Share Posted August 21, 2015 You're both probably including "renderNav()" somewhere in your _init.php. I wasn't sure about 404 exceptions, but I'm about $page->render(), where the init.php is prepended a second time within a single request, and one cannot create a function of the same name twice. I suggest moving helper functions in an own file and just include them in _init.php via include_once. This will make sure the function is never created more than once. Link to comment Share on other sites More sharing options...
oap Posted August 21, 2015 Author Share Posted August 21, 2015 You're both probably including "renderNav()" somewhere in your _init.php. I wasn't sure about 404 exceptions, but I'm about $page->render(), where the init.php is prepended a second time within a single request, and one cannot create a function of the same name twice. I suggest moving helper functions in an own file and just include them in _init.php via include_once. This will make sure the function is never created more than once. Thanks very much for the suggestion of how to get around it. It seems a bit odd though, since rendernav() came in the sample site included in the PW installation - i.e. it is expected that _init.php will be used for this sort of thing. Regardless - thanks! Link to comment Share on other sites More sharing options...
LostKobrakai Posted August 21, 2015 Share Posted August 21, 2015 In the default profile it's included in the way I described, I'm not sure why it's otherwise in the beginner profile. Link to comment Share on other sites More sharing options...
louisstephens Posted August 21, 2015 Share Posted August 21, 2015 Yeah, I just looked, and it appears that the config file and there is a line: $config->prependTemplateFile = '_init.php'; How would I go about only including this once? Sorry for all the questions, just not the best at php. Link to comment Share on other sites More sharing options...
LostKobrakai Posted August 21, 2015 Share Posted August 21, 2015 Just take a look at the files inside site-default folder at github. There's a _func.php and a _init.php, which are set up like I explained it. 1 Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now