我正在写一个表格将数据发布到paypal,这很好用,我用隐藏字段创建表单,然后有一个提交按钮,提交一切到paypal.
但是,当用户单击该按钮时,我想要做的更多,例如在数据库中更改其购物车状态.所以,我希望能够在他们点击提交时执行一些代码,然后将数据发布到paypal.
我不想为此使用javascript.
我的方法目前是使用cURL,表单回发到当前页面,然后检查$ _POST数据,执行其他命令,如更新购物车的状态,然后创建curl命令,并发布表单数据贝宝.现在,它成功发布,但浏览器不会发送到paypal.
起初我只是在一个字符串中重新结果,然后回显它,我可以看到帖子成功了,然后我将CURLOPT_FOLLOWLOCATION设置为1,假设这会让浏览器关闭到paypal,但它没有,它似乎是什么从paypal获取一些东西并将其放在我的页面上.
使用cURL是正确的吗?如果是这样,我该如何解决这个问题呢?我想远离javascript,因为只有启用了javascript的用户才能更新购物车.
下面是用于curl的代码,post_data是我创建的数组,然后将键值对读入post_string.
//Set cURL Options
curl_setopt($curl_connection, CURLOPT_CONNECTTIMEOUT, 30);
curl_setopt($curl_connection, CURLOPT_USERAGENT,
"Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)");
curl_setopt($curl_connection, CURLOPT_RETURNTRANSFER, false);
curl_setopt($curl_connection, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($curl_connection, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($curl_connection, CURLOPT_MAXREDIRS, 20);
//Set Data to be Posted
curl_setopt($curl_connection, CURLOPT_POSTFIELDS, $post_string);
//Execute Request
curl_exec($curl_connection);
Run Code Online (Sandbox Code Playgroud) 我一直在看一些关于Spring Framework入门的教程并遇到过这个.完成后,我遇到了以下错误.(我已经更新为使用spring框架的第3版,我仍然遇到同样的错误.
简而言之,我得到一个NullPointerException,我在AutoWired类上调用一个方法.
我的班级是SayHello:
public class SayHello {
private String name;
public void setName(String name) {
this.name = name;
}
public String getName() {
return name;
}
public void greet() {
System.out.println("Hello " + getName());
}
}
Run Code Online (Sandbox Code Playgroud)
然后,我在/src/test/resources/applicationContext.xml中设置以下内容.
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context.xsd">
<context:annotation-config/>
<bean id="hello" class="package.SayHello">
<property name="name" value="John Smith" />
</bean
Run Code Online (Sandbox Code Playgroud)
最后我有AppTest类,我尝试自动测试SayHello对象进行测试.
public class AppTest {
@Autowired
private SayHello hello;
@Test
public void testApp()
{
hello.greet();
Assert.assertTrue( true );
} …Run Code Online (Sandbox Code Playgroud) 我已经创建了一个rails引擎(完整的,不可安装的)来为许多不同的rails应用程序提供模型.我使用Factory Girl Rails来测试这个引擎,测试对于引擎本身都运行良好.
我现在希望能够在包含此引擎的其他应用程序中使用这些工厂.
Gemspec的依赖关系如下所示:
s.add_dependency "rails", "~> 4.0.3"
s.add_dependency "mysql2", "~> 0.3.15"
s.add_development_dependency "rspec-rails", "~> 3.0.0.beta"
s.add_development_dependency "factory_girl_rails", "~> 4.4.1"
s.add_development_dependency "shoulda-matchers", "~> 2.5.0"
Run Code Online (Sandbox Code Playgroud)
我在/spec/factories.rb中定义了我的工厂:
factory :user do
...
end
Run Code Online (Sandbox Code Playgroud)
要将factories.rb添加到factory girl中的定义路径,我将以下内容添加到我的/lib/engine_name/engine.rb文件中:
class Engine < ::Rails::Engine
initializer "model_core.factories", :after => "factory_girl.set_factory_paths" do
FactoryGirl.definition_file_paths << File.expand_path('../../../spec/factories.rb', __FILE__) if defined?(FactoryGirl)
end
end
Run Code Online (Sandbox Code Playgroud)
在我的rails应用程序中,我通过将以下内容添加到Gemfile来包含引擎:
gem 'engine_name', git: "<GIT_LOCATION>"
Run Code Online (Sandbox Code Playgroud)
我还将factory_girl_rails添加到应用程序中(有没有一种方法可以从引擎中公开它?而不是必须在应用程序Gemfile中指定它?).
并且在spec_helper.rb中要求工厂女孩栏:
require 'factory_girl_rails'
Run Code Online (Sandbox Code Playgroud)
现在,当我写下一个控制器测试时,如下所示:
it "saves the user to the database" do
expect{post :create, user: attributes_for(:user)}.to change{User.count}.by(1)
end
Run Code Online (Sandbox Code Playgroud)
我收到错误:"工厂未注册:用户"
我通过打开ruby控制台并运行来仔细检查工厂女孩定义文件路径FactoryGirl.definition_file_paths,我可以在输出中看到来自引擎的factories.rb: …
我正在处理一个 Zend PHP 项目,我正在尝试将代码分离到一个自定义库中,例如“自定义”。目前这主要包括一些自定义表单。
我的文件夹结构如下。
/project root
/Library
/Custom
/Forms
/Account
/Login.php
Base.php
/Zend
...
Run Code Online (Sandbox Code Playgroud)
Login.php 和 Base.php 具有以下命名约定:
class Custom_Form_Account_Login extends Custom_Form_Base
{
}
class Custom_Form_Base extends Zend_Form
{
}
Run Code Online (Sandbox Code Playgroud)
最后,我在 application.ini 文件中放置了以下行
autoloaderNamespaces[] = "Custom_"
Run Code Online (Sandbox Code Playgroud)
然后要创建表单,我在控制器中有这个...
$form = new Custom_Form_Account_Login();
Run Code Online (Sandbox Code Playgroud)
但是,当我加载页面时,我收到一条错误消息,告诉我无法找到 Custom_Form_Account_Login。显示了包含路径,我可以看到“/project root/Library”在那里,所以我对为什么找不到该类感到有些困惑。
我在 application.ini 中尝试了许多不同的行,并且在进行更改后重新启动了服务器,但错误仍然存在。
我尝试过的其他行包括:
autoloadernamespaces[] = "Custom_" //All lowercase
autoloaderNamespaces[] = "Custom" //Without the underscore
autoloaderNamespaces.custom = "Custom_"
autoloaderNamespaces.0 = "Custom_"
Run Code Online (Sandbox Code Playgroud)
如前所述,我使用的是 Zend 1.12。理想情况下,我想在 .ini 文件中配置它。