Beispiel #1
0
 public function redirect()
 {
     //ShortModel::createShort(Request::get('code'));
     $urlRow = ShortModel::getUrlFromDb(Request::get('code'));
     if (!empty($urlRow)) {
         Redirect::out($urlRow->long_url);
     } else {
         Redirect::to('error');
     }
     //Redirect::to('short/index');
 }
Beispiel #2
0
 public static function shortCodeToUrl($code, $increment = true)
 {
     if (empty($code)) {
         throw new Exception("No short code was supplied.");
     }
     if (ShortModel::validateShortCode($code) == false) {
         throw new Exception("Short code does not have a valid format.");
     }
     $urlRow = ShortModel::getUrlFromDb($code);
     if (empty($urlRow)) {
         throw new Exception("Short code does not appear to exist.");
     }
     if ($increment == true) {
         ShortModel::incrementCounter($urlRow["id"]);
     }
     return $urlRow["long_url"];
 }