symfony学习笔记20170117
来源:互联网 发布:陕西网络广告公司 编辑:程序博客网 时间:2024/05/17 06:04
twig
{# app/Resources/views/base.html.twig #}
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>{% block title %}Test Application{% endblock %}</title>
</head>
<body>
<div id="sidebar">
{% block sidebar %}
<ul>
<li><a href="/">Home</a></li>
<li><a href="/blog">Blog</a></li>
</ul>
{% endblock %}
</div>
<div id="content">
{% block body %}{% endblock %}
</div>
</body>
</html>
{{ ... }}
{% ... %}
{# ... #}
/* comment */
syntax. It’s used to add single or multi-line comments. The content of the comments isn’t included in the rendered pages.{# app/Resources/views/blog/index.html.twig #}
{% extends 'base.html.twig' %}
{% block title %}My cool blog posts{% endblock %}
{% block body %}
{% for entry in blog_entries %}
<h2>{{ entry.title }}</h2>
<p>{{ entry.body }}</p>
{% endfor %}
{% endblock %}
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>My cool blog posts</title>
</head>
<body>
<div id="sidebar">
<ul>
<li><a href="/">Home</a></li>
<li><a href="/blog">Blog</a></li>
</ul>
</div>
<div id="content">
<h2>My first post</h2>
<p>The body of the first post.</p>
<h2>Another post</h2>
<p>The body of the second post.</p>
</div>
</body>
</html>
二 创建链接
(1)
# app/config/routing.yml_welcome: path: / defaults: { _controller: AppBundle:Welcome:index }
在twig里,使用path Twig方法来到达上面的路由
<a href="{{ path('_welcome') }}">Home</a>
(2)
# app/config/routing.ymlarticle_show: path: /article/{slug} defaults: { _controller: AppBundle:Article:show }{% for article in articles %} <a href="{{ path('article_show', {'slug': article.slug}) }}"> {{ article.title }} </a>{% endfor %}三 链接静态文件
<img src="{{ asset('images/logo.png') }}" alt="Symfony!" /><link href="{{ asset('css/blog.css') }}" rel="stylesheet" type="text/css" />(1)twig中引入css和js{# app/Resources/views/base.html.twig #}<html> <head> {# ... #} {% block stylesheets %} <link href="{{ asset('css/main.css') }}" rel="stylesheet" /> {% endblock %} </head> <body> {# ... #} {% block javascripts %} <script src="{{ asset('js/main.js') }}"></script> {% endblock %} </body></html>三 模板全局变量
app.security 安全上下文
app.user 当前登录用户对象
app.request request对象
app.session session对象
app.environment 当前环境
app.debug 是否使用的是debug模式
<p>Username: {{ app.user.username }}</p>{% if app.debug %} <p>Request method: {{ app.request.method }}</p> <p>Application Environment: {{ app.environment }}</p>{% endif %}
0 0
- symfony学习笔记20170117
- symfony学习笔记--第一步,安装symfony
- symfony学习笔记20170405 新建symfony项目
- symfony学习笔记-bundle1
- Symfony之mvc学习笔记
- symfony学习笔记--第二步,创建Bundle
- 学习Symfony框架笔记------创建项目
- symfony 学习
- Symfony 学习
- symfony学习笔记20140405-创建自己的bundle
- symfony安装笔记
- Symfony中文学习资源
- Symfony学习文档
- symfony 学习 1 命令
- 今天继续学习symfony
- Symfony学习-01
- symfony
- symfony
- Myeclipse2014 SVN在线安装方法
- spring事务
- android二维码扫描 Zxing 3.X 使用与开启闪关灯
- 第1章 简单工厂模式
- 关于覆写equals与hashCode的问题。
- symfony学习笔记20170117
- 游戏过关
- 剑指offer-面试题7-用两个栈实现队列
- 前端优化之前端工程化
- 登录验证
- 360 mysql-atlas
- 轮播图
- Linux.修改文件权限
- Mysql存储过程查询结果赋值到变量的方法