我不知道为什么我无法让以下工作:
DB::table('twitter_hashtags')->paginate(5);
每次我得到(第二个数字往往不同)
Allowed memory size of 134217728 bytes exhausted (tried to allocate 95735352 bytes)
我尝试使用(18776710),但这没有任何区别
DB::connection()->disableQueryLog();
删除->paginate(5)
没有任何区别。
当我尝试:
DB::select('SELECT * FROM twitter_hashtags');
它工作正常,但我不能在分页选项中使用构建。
有人提出建议吗?
表twitter_hashtags目前有5500条记录。保存了id,tweet_id和hashtag,因此表格太大不会成为问题。
表的大小:
Data 384,0 KB
Index 464,0 KB
Total 848,0 KB
更新
根据要求提供更多信息
这是行动
public function getHashtags()
{
DB::connection()->disableQueryLog(); // With or without does not make a difference
$retweets = DB::table('twitter_hashtags')->paginate(10);
// Show the page
return View::make('twitter/retweets', compact('retweets'));
}
如您所见,我使用转推的视图,问题也出现在转推中,或几乎任何其他表格我试图从这种方式获取数据。
'view'
</pre><? print_r($retweets) ?></pre>
我用来创建表的迁移
public function up()
{
Schema::create('twitter_hashtags', function($table)
{
// Basic run information
$table->increments('id');
$table->string('status_id')->index();
$table->string('hashtag')->index();
// Misc.
$table->timestamps();
});
}
当将内存限制提高到256M
时,这些是响应的前100行左右Illuminate\Database\Query\Builder Object
(
[connection:protected] => Illuminate\Database\MySqlConnection Object
(
[pdo:protected] => PDO Object
(
)
[queryGrammar:protected] => Illuminate\Database\Query\Grammars\MySqlGrammar Object
(
[wrapper:protected] => `%s`
[selectComponents:protected] => Array
(
[0] => aggregate
[1] => columns
[2] => from
[3] => joins
[4] => wheres
[5] => groups
[6] => havings
[7] => orders
[8] => limit
[9] => offset
[10] => unions
)
[tablePrefix:protected] =>
)
[schemaGrammar:protected] =>
[postProcessor:protected] => Illuminate\Database\Query\Processors\Processor Object
(
)
[events:protected] => Illuminate\Events\Dispatcher Object
(
[container:protected] => Illuminate\Foundation\Application Object
(
[booted:protected] => 1
[bootingCallbacks:protected] => Array
(
[0] => Closure Object
(
[parameter] => Array
(
[$app] =>
)
)
[1] => Closure Object
(
[static] => Array
(
[instance] => Illuminate\Log\LogServiceProvider Object
(
[defer:protected] => 1
[app:protected] => Illuminate\Foundation\Application Object
*RECURSION*
)
)
)
[2] => Closure Object
(
[static] => Array
(
[instance] => Illuminate\Mail\MailServiceProvider Object
(
[defer:protected] => 1
[app:protected] => Illuminate\Foundation\Application Object
*RECURSION*
)
)
)
[3] => Closure Object
(
[static] => Array
(
[instance] => Illuminate\Queue\QueueServiceProvider Object
(
[defer:protected] => 1
[app:protected] => Illuminate\Foundation\Application Object
*RECURSION*
)
)
)
[4] => Closure Object
(
[static] => Array
(
[instance] => Illuminate\Translation\TranslationServiceProvider Object
(
[defer:protected] => 1
[app:protected] => Illuminate\Foundation\Application Object
*RECURSION*
)
)
)
更新2
根据要求。这是回复:
Array
(
[total] => 5689
[per_page] => 5
[current_page] => 1
[last_page] => 1138
[from] => 1
[to] => 5
[data] => Array
(
[0] => stdClass Object
(
[id] => 1
[status_id] => 384992474579484672
[hashtag] => Twenterand
[created_at] => 2013-10-01 11:00:02
[updated_at] => 2013-10-01 11:00:02
)
[1] => stdClass Object
(
[id] => 2
[status_id] => 384992323190280192
[hashtag] => Twenterand
[created_at] => 2013-10-01 11:00:03
[updated_at] => 2013-10-01 11:00:03
)
[2] => stdClass Object
(
[id] => 3
[status_id] => 384989174014545921
[hashtag] => PVDA
[created_at] => 2013-10-01 11:00:03
[updated_at] => 2013-10-01 11:00:03
)
[3] => stdClass Object
(
[id] => 4
[status_id] => 384988499188801536
[hashtag] => GR2014
[created_at] => 2013-10-01 11:00:03
[updated_at] => 2013-10-01 11:00:03
)
[4] => stdClass Object
(
[id] => 5
[status_id] => 384986184092356608
[hashtag] => GR2014
[created_at] => 2013-10-01 11:00:03
[updated_at] => 2013-10-01 11:00:03
)
)
)
)
)
更新3
这里是我用于getStatuses的代码
public function getStatuses()
{
// Get all the paginated statuses
$statuses = DB::table('twitter_statuses')
->select('status_id', 'text', 'user_screen_name','datetime','place')
->orderBy('datetime', 'DESC')
->paginate(10);
// Show the page
return View::make('twitter/statuses', compact('statuses'));
}
完整的视图文件
@extends('layouts/default')
{{-- Page title --}}
@section('title')
Twitter Statuses ::
@parent
@stop
{{-- Page content --}}
@section('content')
<h1>Twitter Statuses</h1>
<div class="container">
<table class="table">
<tr>
<th>Datum</th>
<th>Gebruiker</th>
<th>Tweet</th>
<th>Locatie</th>
</tr>
<?php foreach ($statuses as $status): ?>
<tr>
<td>{{ $status->datetime; }}</td>
<td><?php echo $status->user_screen_name; ?></td>
<td><?php echo $status->text; ?></td>
<td><?php echo $status->place; ?></td>
</tr>
<?php endforeach; ?>
</table>
<?php echo $statuses->links(); ?>
</div>
@stop
答案 0 :(得分:1)
我只是遇到了同样的问题。解决方案很简单:只需在查询末尾添加->get();
:
public function getStatuses()
{
// Get all the paginated statuses
$statuses = DB::table('twitter_statuses')
->select('status_id', 'text', 'user_screen_name','datetime','place')
->orderBy('datetime', 'DESC')
->paginate(10)
->get()
;
// Show the page
return View::make('twitter/statuses', compact('statuses'));
}