0
好後,得到幾乎每一件事情的工作在我的代碼laravel 4.1驗證URL輸入
和不錯
我需要幫助有關如何驗證用戶的URL輸入
,如果他沒有插入非網址如何將其前言404頁
,這裏是我的路線文件
Route::get('/', function()
{
return View::make('hello');
});
Route::post('/', function()
{
$url = Input::get('url');
$record = Url::where('urls', '=', $url)->first();
if ($record) {
return View::make('result')
->with('shortend', $record->shortend);
}
function get_uniqe_short_url()
{
$shortend = base_convert(rand(1000,99999), 10, 36);
if (Url::where('shortend', '=' ,$shortend)->first()){
get_uniqe_short_url();
}
return $shortend;
}
$shortend = get_uniqe_short_url();
// otherwise add new row and return shortned url
$row = new URl;
$row->urls = $url;
$row->shortend = $shortend;
$row->save();
// create a results view and present the short url to the usr
if ($row){
return View::make('result')->with('shortend',$shortend);
}
});
Route::get('{shortend}', function($shortend)
{
// query the DB For the row with that short url
$row = Url::where('shortend', '=', $shortend)->first();
// if not found redirect to home page
if (is_null($row)) return Redirect::to('/');
// else grab the url and redirect
return Redirect::to($row->urls);
});
原諒我的許多問題,但我是全新的laravel
感謝您的幫助,現在我會嘗試,我也會在那個網址,你給我,謝謝你幫我 我會回來的,一旦正如我從測試代碼所做的那樣 – Jone
讓我知道它是如何去的,我可以繼續提出問題的建議。 – Sam
好山姆 對不起,我遲到重播,但我有我的辦公室裏這麼多的工作 我將重播其今天 – Jone