[ Pobierz całość w formacie PDF ]
.Theprocessing is primarily about organizing all the data and writing it to the database,either as a new record or as an update of the time stamp if the error is a repeat of onealready stored.After the record is written, the table is pruned so that a maximum ofseven days information is retained.Where a database exception object is supplied,additional fields are completed.This is discussed in more detail shortly.Handling Database ErrorsAs discussed earlier, errors in database operations are handled by throwing anexception.To do that, a suitable exception class is needed:class databaseException extends Exception{public $dbname = '';public $sql = '';public $number = 0;public function __construct ($dbname, $message, $sql,$number, $dbtrace){parent::__construct($message, $number);$this->dbname = $dbname;$this->sql = $sql;$this->dbtrace = $dbtrace;}}In principle, it is usually better to access data using methods rather than publicproperties, but the operations here are very simple.The class is used within thealiroDatabase class when an error is detected:throw new databaseException ($this->DBname, $this->_errorMsg,$this->_sql, $this->_errorNum, aliroRequest::trace());The result is that a new exception object is created, containing information aboutthe database, the error message, the SQL, the error number and a trace of methodor function calls to the point where the error occurs.The trace method is a staticclass method of aliroRequest, provided for convenience of debugging.The generaltrapping of database errors is achieved by placing a try round the code that callsextensions to generate output:[ 276 ] Chapter 13try{.}catch (databaseException $exception){$target = $this->core_item ? $this->core_item :$this->option;$message = sprintf(T_('A database error occurred on %s at %swhile processing %s'), date('Y-M-d'),date('H:i:s'), $target);$errorkey = "SQL/{$exception->getCode()}/$target/$exception->dbname/{$exception->getMessage()}/$exception->sql";aliroErrorRecorder::getInstance()->recordError($message,$errorkey, $message, $exception);$this->redirect('', $message, _ALIRO_ERROR_FATAL);}The detailed code within the try is omitted for clarity.Any database error occurringwithin the try clause will be processed by the catch.This forms up a message andan error key, on similar principles to the PHP error processing described above.Thenthe recordError method is called, just as it was for a PHP error, except this timewe are outside the aliroErrorRecorder class instead of being already within it.The redirect causes processing to be abandoned, and the basic error message to beshown to the user.Page 404 ErrorsAlthough not an error in quite the same sense as we have been using up to now,there is a condition that we must handle, that is the problem of being supplied witha URI that does not work to define a page in our site.The name 404 error comes fromthe fact that a web server that cannot return a page for a given URI is required toreturn an HTTP header containing an error with the number 404.In some cases, this processing can still be done by the web server (such as Apache)but in other cases the URI will be of a form that appears legitimate until someprocessing has been done by our CMS.In this case, we can still come to theconclusion that the URI is illegal.It is important to give a suitable message to theuser and it is also useful to record these errors as they sometimes indicate incorrectlinks within our own site or links that have been stored by search engines but havebecome invalid because of changes in our site.[ 277 ] Error HandlingThe error can be detected at various possible points, but once detected, Aliro dealswith it by use of a dedicated aliroPage404 class.A much simplified version of thecode of the class is shown here:class aliroPage404{public function __construct (){if (aliroComponentHandler::getInstance()->componentCount() ANDaliroMenuHandler::getInstance()->getMenuCount('mainmenu')){header ('HTTP/1.1 404 Not Found');$this->record404();$searchtext = $this->searchuri();aliroRequest::getInstance()->setPageTitle(T_('404 Error - page not found'));echo id;if ($this->id){$this->modified = date('Y-m-d H:i:s');$this->modify_id = $userid;}[ 292 ] Chapter 14else{$this->created = date('Y-m-d H:i:s');$this->author_id = userid;}parent::store($updateNulls);}}Much of the hard work is done in the parent class, aliroDatabaseRow, which wasdiscussed back in Chapter 5.Because the database framework derives informationfrom the database itself, there is no need to specify the fields that are in the table,which makes it easier to cope with future changes.The minimum that has to be doneis to specify the name of the singleton database class, the name of the table (using asymbol in place of the actual prefix), and to define the name of the primary key field.In this case, the store method is also extended [ Pobierz całość w formacie PDF ]

  • zanotowane.pl
  • doc.pisz.pl
  • pdf.pisz.pl
  • hanula1950.keep.pl