Dispatch Error Handling
There are many situations that result in problems during dispatching of controllers. Ideally, it would be easy to determine when spelling errors or mismatches occur in class names, directory names, and filenames. By examining the user's IP address reported by the web server, additional diagnostic information can be displayed for "local" network requests without interfering with public usage of a website. This section introduces a robust system for managing and reporting common errors, including "404 Page not found" errors.
Install this section by copying "zfdemo/section5_asession/index.php" to the "zfdemo" directory in your web server's document root directory.
Analyzing Dispatch Errors
In "section5_asession/config/config.ini", we change toggle analyzeDispatchErrors by enabling this feature (added below).
There are several possible reasons why an exception might arise after calling "dispatch()". In order to render helpful information after an exception occurred, the exception must be analyzed to discover possible reasons why an exception occurred during routing, dispatching, rendering a view, or otherwise trying to process the module's action controller.
Adding a Custom 404 Error Page
Sending true HTTP 404 error responses to requests for invalid URLs fulfills a critical need of web crawlers to identify invalid URLs and avoid crawling countless invalid pages when a dynamically generated page contains numerous invalid URLs. Humans quickly stop surfing such accidentally created links, but search engines are infamous for getting "lost" amid a maze of pages linking to more invalid pages.
For controller actions, adding a new exception provides an easy way for the action to indicate the request is a "page not found". Remember, some systems cache URI's resulting in 404 HTTP responses, so only issue a 404 when certain that is the desired effect.
After adding the new analyzeError() and the new "404" exception type, it is time to do something about the error by showing the viewer a custom 404 "page not found" message. If the 404 error page should be unique and specific to the action controller requested, and that action controller exists, then use the magic method "__call()" to catch invalid actions and re-route or "_forward()" to a 404 error handler within the action controller:
If the controller does not exist, then the ZFDemo bootstrap will dispatch a 404 error controller, specified in "config/config.ini":
In order to make a default application 404 error handler, the function below is added to the "ErrorController" class in the default controllers directory. The default action is "indexAction", unless explicitly set to something else in the configuration file above. Below, the magic method "__call()" causes all request "actions" to execute the same method, showing a "404" error page. Simply add a new action to the "ErrorController" below, in order to add support for different error pages.
Next, we need to configure a way to dispatch to this "default/controllers/ErrorController.php" action controller by adding the following dispatch code inside the "catch(Exception)" clause in STAGE 2 of "bootstrap.php":
Before dispatching this error controller, a new requet object must be created using the configured module, controller, and action names for the error controller, in order for the normal route process to reach the desired error controller. If files are missing, or a view script contains a syntax error, etc., then the second catch() in STAGE2 (the "catch()" added above) will give our bootstrap the ability to still send a very basic 404 error page using:
Now try a bogus URL, like:
Next Section: 6. Anonymous Sessions
Can someone explane why Safari can't understand:
if ( $this->module !='park' && $this->controller !='fox'){
$this->every->rabbits .= '/indemhole.php';
}
This is from Fierfox:
Tutorial Section: section17_perf | Module: default / Controller: index / Action: index
This is from Safari:
Notice: Key "module" does not exist in /usr/local/apache2/htdocs/wwwpage/library/Zend/View/Abstract.php on line 209
Notice: Key "controller" does not exist in /usr/local/apache2/htdocs/wwwpage/library/Zend/View/Abstract.php on line 209
Notice: Key "action" does not exist in /usr/local/apache2/htdocs/wwwpage/library/Zend/View/Abstract.php on line 209
Is this maybe a bug from the fro?t?
much thanx for any help.
section5_except CORRECTIONS
LOC: index.php
ERR: function name '_' not allowed by php ![]()
OLD: function _($msg)
NEW: function _x($msg)
Search and replace all occurences of '_(' with '_x(' in all files in dir 'section5_except/'
LOC: index.php
ERR: paths doesn't work
OLD: //ZFDemoGrub('section5_except', 'sandbox'); [comment out]
NEW: ZFDemoGrub('/Users/marcgrue/Sites/zfdemo/section5_except/', 'sandbox'); [uncomment this line - use an absolute path]
LOC: index (from section4_mvc)
ERR: php errors not showing for debugging (with my general php_ini settings)
NEW: ini_set('display_errors', true); [add this line before/after the line 'error_reporting(E_ALL|E_STRICT);']
LOC: section5_except/bootstap.php::stage1() ca line 170
ERR: fatal error: Zend_View class declared twice
OLD: require 'Zend/View.php';
NEW: require_once 'Zend/View.php';
LOC: section5_except/bootstap.php::stage1() ca line 191
ERR: Going to 'Forums': wrong (empty) view object is rendered, so no topics are shown
NEW: $frontController->setParam('noViewRenderer', true); [add this line just before returning the $frontController]
LOC: section5_except/bootstap.php::stage2() ca line 287
ERR: '/index.php' added unnecessarily to baseurl
OLD: $baseUrl .= '/index.php';
NEW: $baseUrl .= '/';
LOC: section5_except/default/controllers/IndexController.php::indexAction() ca line 29
ERR: '/index.php' added unnecessarily to baseurl
OLD: $this->view->baseUrl .= '/index.php';
NEW: //$this->view->baseUrl .= '/index.php'; [comment out]
LOC: section5_except/forum/controllers/Index::redirectToTopics() ca line 121
ERR: link to forums is silently redirected back to 'home'
OLD: $this->setRedirectCode(303);
NEW: //$this->setRedirectCode(303); [uncomment]
ALTERNATIVE: add "/topics" to Forums link in zfdemo/index.php
LOC: section5_except/forum/models/pdo/Topics.php::getPresentationModel() ca line 33
ERR: Zend_Date not loaded
NEW: require_once 'Zend/Date.php'; [add line]
LOC: section5_except/forum/models/pdo/Posts.php::getPostsByTopicId() ca line 58
ERR: Zend_Date not loaded
NEW: require_once 'Zend/Date.php'; [add line]
ZF Home Page
Code Browser
Wiki Dashboard
I can't get Section5 or Section4_mvc to work.
I get the following error: