We use cookies to improve your experience. No personal information is gathered and we don't serve ads. Cookies Policy.

ExpressionEngine Logo ExpressionEngine
Features Pricing Support Find A Developer
Partners Upgrades
Blog Add-Ons Learn
Docs Forums University
Log In or Sign Up
Log In Sign Up
ExpressionEngine Logo
Features Pro new Support Find A Developer
Partners Upgrades
Blog Add-Ons Learn
Docs Forums University Blog
  • Home
  • Forums

[EE3/4] Error if enable_template_routes == 'y' but no end points are defined

Developer Preview

Brian Litzinger's avatar
Brian Litzinger
693 posts
7 years ago
Brian Litzinger's avatar Brian Litzinger

In the Template.php file there is the following line:

if (ee()->config->item('enable_template_routes') == 'y')

But the issue is if there are no routes defined, and its enabled, it’ll eventually throw an exception:

Exception: Template route not found. in /var/www/html/system/ee/legacy/libraries/Template_router.php on line 53
Call Stack
# Time Memory Function Location
1 0.0010 367224 {main}( ) .../index.php:0
2 0.0024 368536 require_once( '/var/www/html/system/ee/EllisLab/ExpressionEngine/Boot/boot.php' ) .../index.php:172
3 0.0401 482608 EllisLab\ExpressionEngine\Core\Core->run( ) .../boot.php:146
4 0.0548 572792 EllisLab\ExpressionEngine\Core\Core->runController( ) .../Core.php:109
5 0.7794 2360704 call_user_func_array:{/var/www/html/system/ee/EllisLab/ExpressionEngine/Core/Core.php:229} ( ) .../Core.php:229
6 0.7794 2361096 EE->index( ) .../Core.php:229
7 0.7794 2361096 EE_Core->generate_page( ) .../ee.php:62
8 0.8478 2592624 EE_Template->run_template_engine( ) .../Core.php:656
9 0.8479 2594352 EE_Template->fetch_and_parse( ) .../Template.php:160
10 0.8479 2594384 EE_Template->parse_template_uri( ) .../Template.php:207
11 0.8494 2594384 EE_Template_Router->match( ) .../Template.php:2184

So why not make sure there are end_points before trying to process them? I suggest changing that line to this:

if (ee()->config->item('enable_template_routes') == 'y' && !empty(ee()->template_router->end_points))

I don’t see any downside here because the exception thrown doesn’t tell the user “hey, maybe you should define some routes if you’re going to enable them”

Thoughts?

       
Kevin Cupp's avatar
Kevin Cupp
791 posts
7 years ago
Kevin Cupp's avatar Kevin Cupp

That exception should be caught as it’s in a try/catch. Is it still making it through some how?

Otherwise, in order to check the endpoints in this conditional, the downside I see is we have to load the template router lib and make a DB call even if template routes aren’t enabled. The processing going on in match() is trivial if there are no end-points, so I don’t really mind if the code makes it to match(). If anything, throwing an Exception seems a little dramatic.

       

Reply

Sign In To Reply

ExpressionEngine Home Features Pro Contact Version Support
Learn Docs University Forums
Resources Support Add-Ons Partners Blog
Privacy Terms Trademark Use License

Packet Tide owns and develops ExpressionEngine. © Packet Tide, All Rights Reserved.