Last active
October 20, 2017 00:02
-
-
Save headzoo/cbe987903e240f090ec8c3a72e90ffff to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{% extends "AppBundle::base.html.twig" %} | |
{% block title %}Something{% endblock %} | |
{% block body %} | |
<h1>Favorites</h1> | |
<p>Here are you favorites.</p> | |
<div id="favorites-container"> | |
{% include "AppBundle:user:favorites_list.html.twig" %} | |
</div> | |
<button id="load-btn">Next Page</button> | |
{% endblock %} | |
{% block javascripts %} | |
{{ parent() }} | |
<script type="text/javascript"> | |
$("#load-btn").on("click", function() { | |
fetch('/u/headzoo/favorites') | |
.then(function(resp) { | |
$('#favorites-container').html(resp); | |
}); | |
}); | |
</script> | |
{% endblock %} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<ul> | |
{% for e in events %} | |
<li>{{ e }}</li> | |
{% endfor %} | |
</ul> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
class UserController extends Controller | |
{ | |
/** | |
* @Route("/u/{username}/favorites", name="profile_favorites") | |
* | |
* @param string $username | |
* @return Response | |
*/ | |
public function favoritesAction(Request $request, $username) | |
{ | |
$em = $this->getDoctrine()->getManager(); | |
$user = $this->findUserOrThrow($username); | |
// Get the last 25 videos the user favorited. | |
$events = $em->getRepository("AppBundle:Favorite") | |
->findByUser($user, 25); | |
// For ajax requests, send the list of favorites as a "snippet" of html. | |
if ($request->isXmlHttpRequest()) { | |
return $this->render("AppBundle:user:favorites_list.html.twig", [ | |
"user" => $user, | |
"events" => $events | |
]); | |
// Otherwise send the whole page. | |
} else { | |
return $this->render("AppBundle:user:favorites.html.twig", [ | |
"user" => $user, | |
"events" => $events | |
]); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment