jonom / silverstripe-betternavigator

Front-end utility menu for SilverStripe websites featuring administration and development tools
60 stars 31 forks source link

Error on page controllers that don't have a model #6

Closed jedateach closed 10 years ago

jedateach commented 10 years ago

Some controllers don't have an associated model, such as when registering for an event using the eventregistration module. It constructs a controller with no associated page. The navigator breaks in these cases.

Mind you, this appears to be an issue with the default SilverStripeNavigator.

Fatal error: Wrong parameters for Exception([string $exception [, long $code [, Exception $previous = NULL]]]) in /...../cms/code/controllers/SilverStripeNavigator.php on line 28
Call Stack
#   Time    Memory  Function    Location
1   0.0006  283848  {main}( )   ../main.php:0
2   0.0521  9456776 Director::direct( ) ../main.php:176
3   0.0569  10344664    Director::handleRequest( )  ../Director.php:153
4   0.0594  10546192    ModelAsController->handleRequest( ) ../Director.php:367
5   0.1307  16381000    ContentController->handleRequest( ) ../ModelAsController.php:78
6   0.1389  17450936    ContentController->handleRequest( ) ../ContentController.php:179
7   0.1463  18214624    ContentController->handleRequest( ) ../ContentController.php:179
8   0.1468  18220160    Controller->handleRequest( )    ../ContentController.php:198
9   0.1666  18515784    RequestHandler->handleRequest( )    ../Controller.php:153
10  0.1810  19350520    ContentController->handleRequest( ) ../RequestHandler.php:222
11  0.1832  19358920    Controller->handleRequest( )    ../ContentController.php:198
12  0.1885  19362800    RequestHandler->handleRequest( )    ../Controller.php:153
13  0.1900  19500856    ContentController->handleRequest( ) ../RequestHandler.php:222
14  0.1922  19507400    Controller->handleRequest( )    ../ContentController.php:198
15  0.2557  24304960    RequestHandler->handleRequest( )    ../Controller.php:153
16  0.2561  24307456    Controller->handleAction( ) ../RequestHandler.php:200
17  0.2561  24308800    RequestHandler->handleAction( ) ../Controller.php:194
18  0.2561  24309152    EventRegisterController->index( )   ../RequestHandler.php:288
19  0.3099  26044984    SSViewer->process( )    ../EventRegisterController.php:92
20  0.3734  29543016    SSViewer->includeGeneratedTemplate( )   ../SSViewer.php:1064
....
29  0.5139  29965032    ViewableData->obj( )    ../ViewableData.php:403
30  0.5139  29965080    ContentController->SilverStripeNavigator( ) ../ViewableData.php:363
31  0.5159  30270368    SilverStripeNavigator::get_for_record( )    ../ContentController.php:307
32  0.5159  30270864    SilverStripeNavigator->__construct( )   ../SilverStripeNavigator.php:81
33  0.5159  30326696    __construct ( )
jonom commented 10 years ago

@jedateach Maybe changing line 29 in BetterNavigator.php from if($this->owner && $this->owner->dataRecord) to if($this->owner && $this->owner->dataRecord && $this->owner->ID > 0) would help? Can you let me know if this works? Would prevent the navigator being shown though.

jedateach commented 10 years ago

@jonom: Turns out I diagnosed this slightly wrong.

The error is thrown when dataRecord is a class that doesn't implement CMSPreviewable, in this case ViewableData_Customised.

This works as a fix, but also hides the navigator.

if($this->owner && $this->owner->dataRecord && $this->owner->dataRecord instanceof SiteTree) {

I still think this is something that needs to be resolved in SilverStripeNavigator.