为什么PHP允许嵌套函数?
<?php
function foo() {
function bar() {
return "bar";
}
return "foo";
}
print foo();
print bar();
Run Code Online (Sandbox Code Playgroud)
..是有效的PHP.
但:
我今天碰到了这个,因为我在某个地方忘记了一个结束括号,而且还有一个太多了.代码有效,没有错误抛出; 但这一切都开始表现得非常奇怪.函数未被声明,回调变得狂暴等等.这是一个功能,如果是这样,目的是什么?还是有些特质?
答:评注者指出,这是一个重复的哪些PHP嵌套函数.
Drupal的一个问题一般是它很慢.我们在高流量生产环境中运行Pressflow 6,它为其大小的站点消耗了大量资源.
Drupal 7是否比Drupal 6慢得多:http: //drupal.org/node/615822
看来,这是事实确实如此,但任何人可以证实?
非常感谢,克里斯.
我正在为Vim的Drupal开发寻找有用的脚本,vim配置和插件.
我对各种剧本,个人收藏等的经历特别感兴趣.
从有用的Vim插件进行Web开发和设计(php,html,css,javascript)?
Taglist帮助查看/导航源,在状态区域中显示呼叫签名.
与Drupal texmate捆绑的Snipmate snipmate .
如何在未通过验证时停止Rails更改我的代码.
每次铁路包裹我的田地
<div class='field_with_error'>...</div>
Run Code Online (Sandbox Code Playgroud)
我可以编辑fields_with_error课程
.fields_with_error{ display: inline }
Run Code Online (Sandbox Code Playgroud)
这是有效的,但它是hacky
使用MongoID在Rails中标记的好方法是什么?
似乎只是在文档中添加哈希或数组非常简单,但我不确定这是否是最好的方法.
也许有些宝石?或者是嵌套文档的简单技巧?
是否有一个技巧或脚本可以让我轻松地在vim-plugins和-settings集之间切换?
我使用vim进行非常不同的开发和编写.例如,当在LaTeX中编写报告时,某些特定于web开发的插件出现可能会非常烦人.
我希望看到的是RVM之类的东西.
我document在我的Post模型中添加了一列,所以现在我可以添加txt文件了:
post.rb:
has_attached_file :document
validates_attachment_content_type :document, :content_type => 'text/plain'
Run Code Online (Sandbox Code Playgroud)
安慰:
#<Post id: 92, content: "document upload test", user_id: 1, created_at: "2013-01-02 10:23:13", updated_at: "2013-01-02 10:23:13",
title: "document upload test", document_file_name: "test.txt",
document_content_type: "text/plain", document_file_size: 15,
document_updated_at: "2013-01-02 10:23:13">
Run Code Online (Sandbox Code Playgroud)
所以现在,我想将内容test.txt转换为原始文本.所以我可以在我的控制器中做这样的事情:
@post.content = [TEXT INSIDE test.txt]
有什么建议?
我有一个rspec规范:
require "spec_helper"
describe ApplicationHelper do
describe "#link_to_cart" do
it 'should be a link to the cart' do
helper.link_to_cart.should match /.*href="\/cart".*/
end
end
end
Run Code Online (Sandbox Code Playgroud)
和ApplicationHelper:
module ApplicationHelper
def link_to_cart
link_to "Cart", cart_path
end
end
Run Code Online (Sandbox Code Playgroud)
这在访问站点时有效,但规范失败,并显示有关路由的RuntimeError不可用:
RuntimeError:
In order to use #url_for, you must include routing helpers explicitly. For instance, `include Rails.application.routes.url_helpers
Run Code Online (Sandbox Code Playgroud)
因此,我Rails.application.routes.url在我的规范中包含了spec_helper-file,甚至包括ApplicationHelper它本身,都无济于事.
编辑:我正在通过spork运行测试,也许这与它有关并导致问题.
在使用Spork运行时,如何包含这些路线助手?
一个相关的问题 意味着我可以在我的集成测试中使用令牌认证来测试请求,如下所示:
get "/v1/sites", nil, :authorization => "foo"
assert_response :success
Run Code Online (Sandbox Code Playgroud)
出于某种原因,标题无法访问我的应用程序:
get "/v1/sites", nil, :authorization => "foo"
assert_match response.headers, /foo/
Expected {"X-Frame-Options"=>"SAMEORIGIN", "X-XSS-Protection"=>"1; mode=block", "X-Content-Type-Options"=>"nosniff", "X-UA-Compatible"=>"chrome=1", "WWW-Authenticate"=>"Token realm=\"Application\"", "Content-Type"=>"text/html; charset=utf-8", "Cache-Control"=>"no-cache", "X-Request-Id"=>"23915302-9cfe-424d-86fe-5d60bc0d6b2c", "X-Runtime"=>"0.054857", "Content-Length"=>"27"} to match /foo/.
Run Code Online (Sandbox Code Playgroud)
授权标头无法通过,我可以throw response.headers在控制器中放置时确认.当我用例如卷曲测试时,我确实看到标题出现了.在那里,我甚至可以设置令牌并获得访问权限.控制器的相关代码是:
module V1
class SitesController < ApplicationController
before_filter :restrict_access, :only => :index
def index
head :success
end
private
def restrict_access
authenticate_or_request_with_http_token do |token, options|
token == "foo"
end
end
end
end
Run Code Online (Sandbox Code Playgroud)
这是最小的,在Rails 4上,使用 Rails-API
作为参考,这里是中间件堆栈,它比大多数默认的Rails应用程序更加纤薄.
use ActionDispatch::Static …Run Code Online (Sandbox Code Playgroud) 我正在使用Wicked,它在完成向导后重定向到自定义链接.第二次重定向会发生这种情况.
因此,PUT update触发a 302到/ orders/1/finish_wicked,然后重定向到/ orders/1.这可以按预期工作,但很难在我的控制器测试中测试.
it "must redirect to the order" do
put :update
assert_redirected_to "/orders/1/finish_wicked" #=> This passes, but I am not interested in this
assert_redirected_to order #=> This fails, yet, in the end, the user is being redirected here.
end
Run Code Online (Sandbox Code Playgroud)
如何在功能控制器测试中测试第二个重定向?
现在,我将它分成两个测试:
describe "finalize" do
it "should redirect to the wicked_finish page" do
put :update, id: :finalize, order_id: order.id, order: { accepted: true }
assert_redirected_to controller: "build", action: :update, id: :wicked_finish, order_id: …Run Code Online (Sandbox Code Playgroud)