我想在一个twig块中生成表头并在页面中重复使用它们,这个页面有大约5个不同的表,大致相同的标题.块代码是这样的:
{% block table_headers %}
<th>Fiscal Year</th>
<th>End Date</th>
<th>Period Length</th>
{% for item in result.FinancialStatements.COAMap.mapItem %}
{% if item.statementType == statementType %}
<th>{{ item._ }} ({{ item.coaItem }})</th>
{% endif %}
{% endfor %}
{% endblock %}
Run Code Online (Sandbox Code Playgroud)
上面代码中的关键字是
{% if item.statementType == statementType %}
Run Code Online (Sandbox Code Playgroud)
我想传递statementType作为参数,我正在渲染块,如下所示:
{% render block.table_headers with {'statementType': 'INC'} %}
Run Code Online (Sandbox Code Playgroud)
但这不起作用.我希望将块及其渲染保留在同一个文件中(但不同的块),以保持概念上的接近.
甚至可以使用这样的块吗?我查看了Symfony2文档,找不到任何暗示可以做到这一点的内容,但对我来说这似乎是一个明显的块使用方式.
我正在编写一个简单的Lua脚本来计算Redis 2.8中排序集(http://redis.io/commands/#sorted_set)的中位数.脚本如下
local cnt = redis.call("ZCARD", KEYS[1])
if cnt > 0 then
if cnt%2 > 0 then
local mid = math.floor(cnt/2)
return redis.call("ZRANGE", KEYS[1], mid, mid)
else
local mid = math.floor(cnt/2)
local vals = redis.call("ZRANGE", KEYS[1], mid-1, mid)
return (tonumber(vals[1]) + tonumber(vals[2]))/2.0
end
else
return nil
end
Run Code Online (Sandbox Code Playgroud)
问题是当结果应该是float时,脚本总是返回一个整数.结果是错误的.
$ redis-cli zrange floats 0 100
1) "1.1"
2) "2.1"
3) "3.1"
4) "3.4975"
5) "42.63"
6) "4.1"
$ redis-cli EVAL "$(cat median.lua)" 1 floats
(integer) 3
Run Code Online (Sandbox Code Playgroud)
正确的结果应该是(3.1 + 3.4975)/2.0 …
我在Ubuntu10.10上设置了nginx 0.7.67以及php-cli.我正在尝试运行基于前端控制器的PHP框架,但除index.php之外的所有页面都会出现403错误.
例如:
我的/ etc/nginx/sites-enabled/default如下
server {
listen 80;
server_name mysite.com;
access_log /var/log/nginx/access.log;
error_log /var/log/nginx/error.log warn;
index index.php index.html;
root /full/path/to/public_html;
location ~* \.(js|css|png|jpg|jpeg|gif|ico|html)$ {
expires max;
}
location ~ index.php {
include /etc/nginx/fastcgi_params;
keepalive_timeout 0;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_pass 127.0.0.1:9000;
}
}
Run Code Online (Sandbox Code Playgroud)
有关如何解决上述问题的任何建议?
PS:这是错误日志中的条目
2010/10/14 19:56:15 [error] 3284#0: *1 open() "/full/path/to/public_html/styles/style.css"
failed (13: Permission denied), client: 127.0.0.2, server: quickstart.local,
request: "GET /styles/style.css HTTP/1.1", host: "mysite"
Run Code Online (Sandbox Code Playgroud) 我试图在Mongo shell中做一个简单的map reduce,但是reduce函数永远不会被调用.这是我的代码:
db.sellers.mapReduce(
function(){ emit( this._id, 'Map') } ,
function(k,vs){ return 'Reduce' },
{ out: { inline: 1}})
Run Code Online (Sandbox Code Playgroud)
结果是
{
"results" : [
{
"_id" : ObjectId("4da0bdb56bd728c276911e1a"),
"value" : "Map"
},
{
"_id" : ObjectId("4da0df9a6bd728c276911e1b"),
"value" : "Map"
}
],
"timeMillis" : 0,
"counts" : {
"input" : 2,
"emit" : 2,
"output" : 2
},
"ok" : 1,
Run Code Online (Sandbox Code Playgroud)
}
怎么了?
我在Ubuntu 10.10上使用MongoDB 1.8.1 32位
我可以通过"工具">"模板管理器"编辑PHP类模板,然后编辑"PHP类">"编辑".我的项目框架支持使用命名空间自动加载,所以我想在创建新的"PHP类"时自动将命名空间添加到文件的顶部.我怎样才能做到这一点?
作为一方,我怎样才能找出模板中可用的变量?
我在使用strophe的'attach()'函数时遇到了很多困难.
我正在一个社交网络上工作,用户将浏览网页,同时保持聊天连接.我不想重新连接/每一页上重新授权,以便按照该链接,http://groups.google.com/group/strophe/browse_thread/thread/430da5e788278f3a/93c48c88164f382f?show_docid=93c48c88164f382f&fwc=1,我存储SID和RID成为一个cookie onunload.
在下一页,当我尝试使用新的SID和RID(在将其递增1之后)时,我的会话已被销毁.Ejabberd报告"HTTP放置错误.原因:bad_key"
WTF正在发生?
有没有办法在mongo中创建用户定义的Javascript函数.我在客户端有几个Map/Reduce函数,我想在其他MR函数中使用.
例如,几个MR函数计算各种平均值.我希望能够像这样使用它们:
function reduce(k,v)
{
if (val > myDatabaseAverage())
// ..do something
}
Run Code Online (Sandbox Code Playgroud) 我有一组服务器登陆到局域网.我能够在机器上安装和使用LXD容器,但是对于我来说,我无法在网络上看到容器.我试图关注这些网址,但无济于事:
我的服务器设置如下:
如果我尝试通过lxdbr0在eth1设备上设置网桥,则容器在LAN上不可见.如果我尝试br0手动设置桥接设备,桥接到eth1并使用DHCP,则设备无法启动.
我的/ etc/network/interfaces看起来像这样:
iface lo inet loopback
# The primary network interface
iface eth0 inet static
address x.x.x.x
netmask 255.255.255.224
gateway x.x.x.x
iface eth1 inet static
address 192.168.0.61/23
iface br0 inet dhcp
bridge_ports eth1
bridge-ifaces eth1
bridge_stp off
bridge_fd 0
bridge_maxwait 0
auto lo eth0 eth1 br0
Run Code Online (Sandbox Code Playgroud)
是否可以创建在LAN上可见的容器并可以连接到Internet?
UXntu 16.04上的LXD v2.7