首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >Laravel4.2不返回视图::make

Laravel4.2不返回视图::make
EN

Stack Overflow用户
提问于 2017-04-19 09:24:10
回答 1查看 292关注 0票数 0

好的,拉拉维尔4.2;MariaDB;等

尝试查询sql字符串"test“时,我知道它在那里,因为我创建了它。

这是我的SearchController.php代码:

代码语言:javascript
运行
复制
 // 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.");
            }
        }

这是我的课堂代码

代码语言:javascript
运行
复制
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;
}

}

这是我的路线

代码语言:javascript
运行
复制
Route::controller('getIndex', 'SearchController');
Route::controller('/search', 'SearchController');
Route::resource('getIndex', 'SearchController');
Route::controller('/user', 'UserController');
Route::controller('/maintenance', 'MaintenanceController');

我在mysql中正确的表和数据库中创建了字符串"test“;一切都很好。但是当我试图查询"test“时,它会返回”没有找到的结果“;即使是这样,我也清楚地看到了它。

如果这有帮助的话,可以使用Idk;但是下面是我发现的一个有趣的分析器部分:

谢谢你的进阶!

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2017-04-19 09:32:07

如果第一次调用processSearch给出了值,则不会返回任何视图。

代码语言:javascript
运行
复制
$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));
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/43491546

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档