[英]Laravel 4.2 Not Returning View::make
Okay so Laravel 4.2; 好的,Laravel 4.2; MariaDB;
MariaDB的; ect
ECT
Trying to query a sql string "test", i know it's there since i created it. 尝试查询sql字符串“ test”,因为我创建了它,所以我知道它在那里。
Here's my SearchController.php code: 这是我的SearchController.php代码:
// Here search is ok.
$start = microtime(true);
$items = Project::processSearch('+' . implode(' +', $searchTerms), false, $this->limitPerPage, $page, $this->maxSearchResults);
$executionTime = microtime(true) - $start;
$total = $items->getTotal();
if($total == 0)
{
$start = microtime(true);
$items = Project::processSearch(implode(' ', $searchTerms),
true, $this->limitPerPage, $page, $this->limitPerPage);
$executionTime = microtime(true) - $start;
$total = $items->getTotal();
if($total > 0)
{
return View::make('search.results')
->with('items', $items)
->with('executionTime', number_format($executionTime, 4))
->with('info', "Your query didn't return any result.");
}
}
here's my class code 这是我的班级代码
public static function processSearch($query, $suggestions, $resultsPerPage, $page, $limit = null)
{
$slug = Str::slug($query) . '-general';
$slug .= $suggestions ? '-suggestions' : '-exact-search';
$results = Cache::remember($slug, 10, function() use($query, $limit)
{
$items = Project::whereRaw(
"MATCH(mixed) AGAINST(? IN BOOLEAN MODE)",
array($query)
)->take(301);
if(Auth::check())
{
$items = $items->with(['unlockedItemsUser' => function($query)
{
$query->where('user_id', '=', Auth::user()->id);
}]);
}
if($limit != null)
{
$items = $items->limit($limit);
}
$items = $items->get();
if(count($items) > 0 && is_object($items))
{
return $items->all();
}
return null;
});
if($results != null)
{
$pages = objectlist_chunk($results, $resultsPerPage);
return Paginator::make($pages[$page - 1], count($results), $resultsPerPage);
}
return Paginator::make(array(), 0, $resultsPerPage);
}
public function unlockedItemsUser()
{
return $this->hasMany('UnlockedItem', 'item_id', 'id');
}
public function newQuery($excludeDeleted = false)
{
$query = parent::newQuery();
if($excludeDeleted)
{
$query->where('deleted', '=', '0');
}
$query->where('blacklist', '=', 0);
return $query;
}
} }
Here's my routes 这是我的路线
Route::controller('getIndex', 'SearchController');
Route::controller('/search', 'SearchController');
Route::resource('getIndex', 'SearchController');
Route::controller('/user', 'UserController');
Route::controller('/maintenance', 'MaintenanceController');
I created the string "test" In mysql inside the correct table and database; 我在正确的表和数据库中的mysql中创建了字符串“ test”; everything is fine.
一切顺利。 But when i try to query "test" it returns with "No results found";
但是,当我尝试查询“测试”时,它返回“未找到结果”; even tho i clearly see it.
即使我也清楚地看到它。
Idk if this helps; 如果这有帮助,请确认; but here's a profiler section i found interesting:
但是这是我发现有趣的探查器部分:
thank you in advanced! 在此先感谢您!
You are not returning any view if your first call to processSearch
give you value. 如果您对
processSearch
的第一次调用给您带来了价值,那么您将不返回任何视图。
$start = microtime(true);
$items = Project::processSearch('+' . implode(' +', $searchTerms), false, $this->limitPerPage, $page, $this->maxSearchResults);
$executionTime = microtime(true) - $start;
$total = $items->getTotal();
if($total == 0)
{
$start = microtime(true);
$items = Project::processSearch(implode(' ', $searchTerms),
true, $this->limitPerPage, $page, $this->limitPerPage);
$executionTime = microtime(true) - $start;
$total = $items->getTotal();
if($total > 0)
{
return View::make('search.results')
->with('items', $items)
->with('executionTime', number_format($executionTime, 4))
->with('info', "Your query didn't return any result.");
} else {
return View::make('search.results')
->with('items', $items)
->with('executionTime', number_format($executionTime, 4))
->with('info', 'There is nothing to show');
}
}
return View::make('search.results')
->with('items', $items)
->with('executionTime', number_format($executionTime, 4));
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.