Skip to content

Instantly share code, notes, and snippets.

@NakanoMakoto
Last active June 1, 2019 13:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save NakanoMakoto/52b5dfd184caaf206a20f438f1e51605 to your computer and use it in GitHub Desktop.
Save NakanoMakoto/52b5dfd184caaf206a20f438f1e51605 to your computer and use it in GitHub Desktop.
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