在PHP中处理SOAP标头(Process SOAP Headers in PHP)
我正在构建(在PHP中)一个SOAP服务器,它由WSDL配置为接受如下所示的消息:
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns1="https://my.awesome.namespace/"> <SOAP-ENV:Header> <ns1:Header> <ns1:APIKey>E4C5BDE0-48DC-543C-1CA3-8E55C63F8E60</ns1:APIKey> <ns1:SiteID>111</ns1:SiteID> </ns1:Header> </SOAP-ENV:Header> <SOAP-ENV:Body> <ns1:Heartbeat> <ns1:Message>Hello world.</ns1:Message> </ns1:Heartbeat> </SOAP-ENV:Body> </SOAP-ENV:Envelope>
让我的SOAPServer处理Heartbeat消息没问题 -
$server->addFunction("Heartbeat");
工作正常。 但是,我希望能够处理<ns1:Header>
机箱的内容 - 因此我可以验证API密钥和站点ID,以确保它们应该是什么。我看了这里 ,(当然还有其他地方),但响应者似乎错过了问题的重点。 有谁知道我如何访问标题元素来验证? 我是否可以像在身体中使用方法一样为Header添加函数? (
$server->addFunction("Header");
)首先十分感谢。
I am building (in PHP) a SOAP server that is configured by its WSDL to accept messages that look like this:
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns1="https://my.awesome.namespace/"> <SOAP-ENV:Header> <ns1:Header> <ns1:APIKey>E4C5BDE0-48DC-543C-1CA3-8E55C63F8E60</ns1:APIKey> <ns1:SiteID>111</ns1:SiteID> </ns1:Header> </SOAP-ENV:Header> <SOAP-ENV:Body> <ns1:Heartbeat> <ns1:Message>Hello world.</ns1:Message> </ns1:Heartbeat> </SOAP-ENV:Body> </SOAP-ENV:Envelope>
I had no problem getting my SOAPServer to process Heartbeat messages -
$server->addFunction("Heartbeat");
works fine. I want, however, to be able to process the contents of the<ns1:Header>
enclosure - so I can validate the API key and Site ID to make sure they are what they should be.I looked here, (and of course elsewhere) but the responder seems to have missed the point of the question. Does anyone know how I can access the header element to validate? Do I add a function for Header the way I would a method in the body? (
$server->addFunction("Header");
?)Thanks very much in advance.
原文:https://stackoverflow.com/questions/1948897
最满意答案
为了设置非常相似的东西,我使用了以下形式:
<%= form_for [:place, @comment] do |f| %> #form fields here <%= end %>
然后在评论控制器中:
def create @post = Post.find(params[:post_id]) @comment = @post.comments.build(params[:comment]) @comment.user = User.find(current_user.id) respond_to do |format| if @comment.save format.html { redirect_to(@comment.post, :notice => 'Comment was successfully created.') } else format.html { render :action => "new" } end end
结束
这应该有希望地建立协会! 除此之外,您是否意味着将评论嵌套在:路由中的用户? 如果您只想在个人资料页面上显示所有用户的评论,您可以执行以下操作:
<p> <b>Comments</b> <% if @user.comments.empty? %> No comments to display yet... <% else %> <% @user.comments.each do |comment| %> <p> <%= link_to "#{comment.post.title}", post_path(comment.post_id) %>, <%= comment.created_at %> <%= simple_format comment.content %> </p> <% end %> <% end %> </p>
希望其中一些有帮助!
To set up something very similar, I've used the following form:
<%= form_for [:place, @comment] do |f| %> #form fields here <%= end %>
Then in the comments controller:
def create @post = Post.find(params[:post_id]) @comment = @post.comments.build(params[:comment]) @comment.user = User.find(current_user.id) respond_to do |format| if @comment.save format.html { redirect_to(@comment.post, :notice => 'Comment was successfully created.') } else format.html { render :action => "new" } end end
end
That should build the associations properly hopefully! Just as an aside, do you mean for comments to be nested under :users in your routes? If you just want to display all the user's comments on a profile page, you could do something like:
<p> <b>Comments</b> <% if @user.comments.empty? %> No comments to display yet... <% else %> <% @user.comments.each do |comment| %> <p> <%= link_to "#{comment.post.title}", post_path(comment.post_id) %>, <%= comment.created_at %> <%= simple_format comment.content %> </p> <% end %> <% end %> </p>
Hope some of that helps!
相关问答
更多-
是的,这是正确的方法。 Yes that is the correct approach.
-
这取决于你想要的结果: @allusers = User.all # returns all users of the users table @allposts = Post.all # returns all posts of the posts table @user = User.first # returns first user of the users table @posts = @user.posts # returns all posts of the first user of the ...
-
邮件和位置的Rails关联 - has_many和belongs_to(Rails association for post and location - has_many and belongs_to)[2023-07-25]
你得到的错误信息是什么? my_post.location.name 应该工作,只要my_post有一个关联的位置 What is the error message that you are getting? my_post.location.name should work, as far as my_post has an associated Location -
为了设置非常相似的东西,我使用了以下形式: <%= form_for [:place, @comment] do |f| %> #form fields here <%= end %> 然后在评论控制器中: def create @post = Post.find(params[:post_id]) @comment = @post.comments.build(params[:comment]) @comment.user = User.find(current_user.id) ...
-
class User < ActiveRecord::Base belongs_to :clearance, :foreign_key => "clearance" end class Clearance < ActiveRecord::Base has_many :users, :foreign_key => "clearance" end class User < ActiveRecord::Base belongs_to :clearance, :foreign_key => "cle ...
-
我99%肯定是因为您的一个或多个报告没有相关用户。 尝试 <%= report.user.name rescue "none" %> 如果报表上的user_id字段中没有值,则report.user将返回nil。 所以report.user.name就像调用nil.name ,这会引发错误。 更新:这是一个更好的方法: <%= report.user.try(:name) %> I'm 99% sure it's because one or more of your reports do not ha ...
-
各种所属的许多协会(Various belongs_to many associations)[2022-01-28]
为什么不先从规格开始呢? 在轨道上是一个很好的练习,具有rspec的所有功能 您的物品应该被称为邮政,为什么物品? 有什么缘故吗? 如果要将其称为“项目”,则需要在关联上指定 belongs_to :post, class_name: 'Item' 但你最好使用Post而不是Item 评论属于用户,因此用户has_many:评论,您不需要“,通过::帖子”部分 has_many :category_posts has_many :posts, :through => :category_posts #or ... -
Rails 4 belongs_to / has_many关系不起作用(Rails 4 belongs_to/has_many relationship not working)[2023-11-16]
您需要将article_params更改为以下内容 def article_params params.require(:article).permit(:headline, :lede, :body, :type_id, :category_ids => [], :region_ids => [], :story_ids => []) end 请注意更改:type_id => [] to :type_id You need to change the article_params to below ... -
你有没有尝试在你的路线上做这样的事情 resources:requests do resources :proposals end 响应 request_proposals GET /requests/:request_id/proposals(.:format) proposals#index ...
-
我认为您应该更喜欢将对象设置为关系而不是设置它们的ID。 例如,你应该这样做: @comment.user = current_user 代替 @comment.user_id = current_user.id ActiveRecord将负责设置相应的*_id字段。 我不确定它是如何处理反向的。 ( 如果我理解正确,它应该自动加载 ) I think you should prefer setting objects to relations instead of setting their id ...