私はしばらくの間、symfonyに取り組んできましたが、どのように動作するのか理解しようとしています。だから、タスクの配列にいくつのタスクがあるのかを数えようとしました。配列内のオブジェクトを数えるには?
これは私のhomeController.phpクラスです:、
public function succesfulLogin(Request $request)
{
$repository = $this->getDoctrine()->getRepository('AppBundle:Task');
$tasks = $repository->findByAuthor($this->getUser()->getUsername());
$points = 0;
foreach($tasks as $task){
$points++;
}
return $this->render(
'userpage.html.twig',array('username' => $username = $this->getUser()->getUsername(), 'tasks' => $tasks, 'points' => $points));
$user->getTasks();
//as I understant I return '$tasks' array to twig with all my tasks
//so before returning '$tasks' array it should have 21 object in it?(not 13)
//am I wrong?
}
は、だから私は数小枝ための「ポイント」と小枝のプリントを渡し、私はすべてのタスク小枝でを印刷しようとすると、私は21の仕事があると言います。
{% for task in tasks %}//this foreach loop prints out 21 task
<tr>
<td id>{{ task.Id }}</td>
<td>{{ task.Status }}</td>
<td>{{ task.Name }}</td>
<td>{{ task.Description }}</td>
<td>{{ task.Category }}</td>
<td>{{ task.Author }}</td>
<td>{{ task.CreationDate|date("m/d/Y") }}</td>
<td><a id="myLink" href="/edit/{{ task.ID }}" > Edit </a></td>
<td><a id="myLink" href="/delete/{{ task.ID }}" >Delete</a></td>
<?php echo 2+2; ?> </tr>
{% endfor %}
SQLが '$ repository-> findByAuthor(の$ this - >のgetUser() - > getUsername())によって生成されたチェック'、どのSQLが( 'する$ user-> getTasksによって生成される)'としてみてくださいこれらの生のSQLクエリをデータベースに再度実行します。 –
コントローラー内の 'dump($ tasks);'を使って、内部にあるものを確認します。 – COil
@COil答えはどこにありますか?私のウェブで? – David