Tuesday, 21 April 2015

Error Handling on Joomla 3+

On latest version of Joomla (version 3+), the JError class has been depreciated and force to use the default PHP Exception which can be used as below:

 * Function to verify the user access permission.
 * @return bool Return 'TRUE' if user has access, else throw an error.
 * @throws Exception
protected function hasAccessPermission()
 // Fetch the any user session.
 $user = JFactory::getUser(); 
 try {        
  /* if not logged in, prompt error. */
  if (!$user->get('guest')) 
   /* Write your code here.. */
            return true;
  else {
   throw new Exception("You don't have permission to access this page. Please click here to Login for access.");
 // Catch any exception
 catch (Exception $e) {
  // Display the message and exit;

No comments:

Post a Comment

Please post any queries and comments here.