Advertisement
Shaun_B

Always return a string value (Zend framework)

Sep 10th, 2015
432
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.85 KB | None | 0 0
  1. /**
  2.  * @readme  I had an issue recently whereby a telephone number was being interpreted as a number
  3.  *      value in the view with the Zend framework, so 01212112121 in the DB was being
  4.  *      displayed as 1212112121 to the user. It may not be the most elegant solution, but this method works.
  5.  * @author  Shaun B
  6.  * @date    2015-09-10
  7.  */
  8.  
  9. private function getUserPhoneNumber()
  10. {
  11.     $userId         = $this->getUserId();    
  12.     $usersModel         = new Application_Model_DbTable_Users();   
  13.     $userTelephoneNumber    = $usersModel->getUserPhoneNumber($userId);
  14.    
  15.     return is_string($userTelephoneNumber) ? $userTelephoneNumber : "0" . $userTelephoneNumber;
  16. }
  17.  
  18. /**
  19.  * @readme  So, I can now safely pass this to the view with the leading zero, ie:
  20.  */
  21.  
  22. public function userDetailsAction()
  23. {
  24.     ## Some logic...
  25.     $this->view->userTelephoneNumber = $this->getUserPhoneNumber();
  26. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement