Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Symfony-beginner
class DefaultController extends Controller
{
\**
* @Route("/", name="homepage")
*\
public function indexAction() {
return $this->render("index.html.twig",[]);
}
}
{% for message in app.flashes("notice")%}
<div class="flash-notice">
{{ message }}
<div>
{% endfor %}
class DefaultController extends Controller
{
\**
* @Route("/", name="homepage")
*\
public function helloAction(Request $request) {
// Ajaxリクエストからの判定
    $request->isXmlHttpRequest;
// Getパラメータからの取得
    $request->query->get("hoge");
// Postパラメータからの取得
    $request->request->get("hoge");
}
}
{# hello.html.twig}
{% block body %}
<h1>Hi {{name}}!</h1>
{% endblock%}
class DefaultController extends Controller
{
\**
* @Route("/", name="homepage")
*\
public function indexAction() {
return $this->redirectToRoute("hello", ["name" => "test"])
}
}
class DefaultController extends Controller
{
\**
* @Route("/hello/{name}", name="hello")
*\
public function helloAction($name) {
return $this->render("index.html.twig",[
'name' => $name
]);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment