我正在使用doctrine fixtures在我的symfony应用程序中加载测试数据.
$this->fixtureLoader = $this->loadFixtures([
"My\DemonBundle\DataFixtures\ORM\LoadEntity1Data",
"My\DemonBundle\DataFixtures\ORM\LoadEntity2Data",
"My\DemonBundle\DataFixtures\ORM\LoadEntity3Data",
"My\DemonBundle\DataFixtures\ORM\LoadEntity4Data",
"My\DemonBundle\DataFixtures\ORM\LoadEntity5Data",
'My\DemonBundle\DataFixtures\ORM\LoadEntity6Data'
]);
Run Code Online (Sandbox Code Playgroud)
在我的测试用例中,我想测试获取分页实体.
public function testGetPaginated()
{
$entities6 = $this->fixtureLoader->getReferenceRepository()->getReferences();
$expected = array_slice($entities6, 3, 3);
$this->client = static::makeClient();
$this->client->request('GET', '/api/v1/entities6', ["page" => 2, "limit" => 3, "order" => "id", "sort" => "asc"], array(), array(
'CONTENT_TYPE' => 'application/json',
'HTTP_ACCEPT' => 'application/json'
));
$this->assertSame($expected, $this->client->getResponse()->getContent());
}
Run Code Online (Sandbox Code Playgroud)
我想比较我的灯具和api响应的页面.问题是线下返回所有夹具参考.我想测试的实体是Entity6类型.Entity6依赖于所有其他类型,因此我必须加载所有其他类型.
$ entities = $ this-> fixtureLoader-> getReferenceRepository() - > getReferences();
我如何才能获得Entity6类型的推荐?我深入研究
Doctrine\Common\DataFixtures\ReferenceRepository :: getReferences代码
/**
* Get all stored references
*
* @return array
*/ …Run Code Online (Sandbox Code Playgroud) 我正在将 Kohana 中的网站逐渐移植到 Symfony 2。现在我正在 Symfony2 中编写后端命令,例如 cron 来发送电子邮件通知。
如何访问 twig 中的基本 url。我可以做一些配置,以便从控制台和 http 请求访问 twig 中的 url 相同吗?
我已经提到过这一点,
http://symfony.com/doc/current/cookbook/console/sending_emails.html
http://symfony.com/doc/current/cookbook/templated/global_variables.html
这里给出了如何配置它,但没有提到如何访问它,我假设我必须使用 {{ router.request_context.host }} 。
但我的问题是,是否有任何方法可以在 console 和 HTTP 之间保持一致?
例如 {{ url }} ?
我找不到任何使用symfony 2 doctrine 2使用mysql存储过程的例子.下面是我的存储过程的签名,
CREATE PROCEDURE `get_matched_users_by_name` (IN lastname VARCHAR(50), IN firstname VARCHAR(50), IN middlename VARCHAR(50), IN debug INT(11), OUT user_id INT(11), OUT user_name VARCHAR(60))
BEGIN
.....
.....
END
Run Code Online (Sandbox Code Playgroud)
如何调用上面的存储过程并访问输出参数user_id和user_name?
我已经搜索了类似的问题,但是没有找到这样的例子,也被裁判了
http://docs.doctrine-project.org/projects/doctrine-orm/en/latest/reference/native-sql.html#examples
我想将来自 javascript (jquery) 的查询字符串参数附加到 symfony 2 url。我想将选定单选按钮的值传递给 ajax 请求 egin plain php 我会这样做
$(document).ready(function() {
$('.id_radio').click(function() {
$.ajax({
'url': 'example.php?id='+($this).val(),
'success': function(r) {
$('#div1').html(r);
}
});
});
Run Code Online (Sandbox Code Playgroud)
如何在 symfony2 twig 中生成这样的 URL?我们在 symfony 2 twig 中生成 URL,例如
{{ path('example_path', {'id': id}) }} 其中 id 是树枝变量。
我尝试使用 FOSJsRoutingBundle 但不知道它是否是针对同样的问题并且不确定如何使用它?
我在下面尝试过,但它不起作用。
$('.id_radio').click(function() {
alert(Routing.generate('example_path', {
'id': $(this).val()
}));
$.ajax({
'url': Routing.generate('example_path', {
'id': $(this).val()
}),
'success': function(r) {
$('#div1').html(r);
}
});
});
Run Code Online (Sandbox Code Playgroud)
koskoz 在下面提到的解决方案有效,我没有通过 options={"expose"=true} 但在添加后它起作用了。
但还有一个问题。它只在我们不刷新页面之前有效。如果我们刷新页面,它不起作用。为了使它工作,我必须删除 symfony 缓存文件。
如果我们已经在一个浏览器中打开它,它在其他浏览器中不起作用。
{{ render(controller("SomeBundle:Foo:Bar", {HERE I WANT TO PASS ALL query parameters app.request.query.all}) }}
Run Code Online (Sandbox Code Playgroud)
那么我可以在子请求中访问所有主请求查询参数吗?子请求也应该独立运行?
我正在使用spring amqp rabbitmq,并使用发送消息
Message message = MessageBuilder
.withBody(item.toString().getBytes())
.setReplyTo("importReply")
.setCorrelationId(item.toString().getBytes()).build();
Run Code Online (Sandbox Code Playgroud)
我的消息处理程序是
public class Foundation {
public Message importExchange(Message exchange) {
System.out.println("Command:" + exchange.getBody());
Message message = MessageBuilder
.withBody(exchange.getBody().toString().getBytes()).setCorrelationId(exchange.getMessageProperties().getCorrelationId() .toString().getBytes()).build();
return message;
}
}
Run Code Online (Sandbox Code Playgroud)
我已经迷上了它
<rabbit:listener-container
connection-factory="rabbitConnectionFactory" concurrency="10">
<rabbit:listener queues="${rabbitmq.import.queue}"
ref="foundation" method="importExchange" />
<rabbit:listener queues="${rabbitmq.import.reply.queue}"
ref="importExchangeItemWriter" method="replyHandler" />
</rabbit:listener-container>
Run Code Online (Sandbox Code Playgroud)
但是我正在努力
Execution of Rabbit message listener failed, and no ErrorHandler has been set.
org.springframework.amqp.rabbit.listener.ListenerExecutionFailedException: Failed to invoke target method 'importExchange' with argument type = [class [B], value = [{[B@427829d8}]
at org.springframework.amqp.rabbit.listener.adapter.MessageListenerAdapter.invokeListenerMethod(MessageListenerAdapter.java:483)
at …Run Code Online (Sandbox Code Playgroud) 我正在使用 Spring 工具套件,我刚刚将其升级到最新版本spring-tool-suite-3.5.1.RELEASE-e4.3.2-linux-gtk-x86_64,但现在无法启动它。它给出了以下错误:
VM terminated. Exit code=1
/usr/bin/java
-Dosgi.requiredJavaVersion=1.6
-Xms40m
-Xmx768m
-XX:MaxPermSize=256m
-jar /home/vishal/install/sts/sts-3.5.1.RELEASE//plugins/org.eclipse.equinox.launcher_1.3.0.v20130327-1440.jar
-os linux
-ws gtk
-arch x86_64
-showsplash
-launcher /home/vishal/install/sts/sts-3.5.1.RELEASE/STS
-name STS
--launcher.library /home/vishal/install/sts/sts-3.5.1.RELEASE//plugins/org.eclipse.equinox.launcher.gtk.linux.x86_64_1.1.200.v20140116-2212/eclipse_1508.so
-startup /home/vishal/install/sts/sts-3.5.1.RELEASE//plugins/org.eclipse.equinox.launcher_1.3.0.v20130327-1440.jar
--launcher.overrideVmargs
-exitdata 98006
-product org.springsource.sts.ide
-vm /usr/bin/java
-vmargs
-Dosgi.requiredJavaVersion=1.6
-Xms40m
-Xmx768m
-XX:MaxPermSize=256m
-jar /home/vishal/install/sts/sts-3.5.1.RELEASE//plugins/org.eclipse.equinox.launcher_1.3.0.v20130327-1440.jar
Run Code Online (Sandbox Code Playgroud)
我有 ubuntu 12.04 和这个 Java 版本:
java version "1.7.0_25"
Java(TM) SE Runtime Environment (build 1.7.0_25-b15)
Java HotSpot(TM) 64-Bit Server VM (build 23.25-b01, mixed mode)
Run Code Online (Sandbox Code Playgroud)
这是 STS.ini
-vm
/usr/lib/jvm/jdk1.7.0/bin/java
-startup
plugins/org.eclipse.equinox.launcher_1.3.0.v20130327-1440.jar
--launcher.library
plugins/org.eclipse.equinox.launcher.gtk.linux.x86_64_1.1.200.v20140116-2212
-product
org.springsource.sts.ide
--launcher.defaultAction …Run Code Online (Sandbox Code Playgroud) java eclipse spring sts-springsourcetoolsuite spring-tool-suite
区域:
namespace Acme\RegionBundle\Entity;
class Region
{
private $id;
/**
* @ORM\OneToMany(targetEntity="User")
* @ORM\JoinColumn(name="region_id", referencedColumnName="id")
*/
private $users;
}
Run Code Online (Sandbox Code Playgroud)
用户:
namespace Acme\UserBundle\Entity;
class User
{
private $id;
private $region_id;
}
Run Code Online (Sandbox Code Playgroud)
如何在不提及完全指定的实体路径即硬编码依赖性的情况下关联来自不同束的实体.
有没有更好的方法?
可以解决目标实体监听器是一种解决方案.我无法理解它是如何在这里应用的?
我使用的是弹簧批,下面是配置.
<beans:bean id="symfonyJob" class="com.st.symfony.Symfony"
p:dir="${symfony.dir}" p:consolePath="${symfony.console.path}"
p:strUtil-ref="strUtil" p:logFilePath="${batch.log.file.path}.#{jobParameters[batch_id]}" scope="step"/>
<beans:bean id="importExchangesItemWriter"
class="com.st.batch.foundation.ImportExchangesItemWriter"
p:symfony-ref="symfonyJob" p:replyTimeout="${import.exchanges.reply.timeout}" scope="step"/>
<beans:bean id="importExchangesFileItemReader"
class="org.springframework.batch.item.file.MultiThreadedFlatFileItemReader"
p:resource="file:${spring.tmp.batch.dir}/#{jobParameters[batch_id]}/exchanges.txt"
p:lineMapper-ref="stLineMapper" p:startAt="#{stepExecutionContext['startAt']}"
p:maxItemCount="#{stepExecutionContext['itemsCount']}" scope="step" />
<step id="importExchangesStep">
<tasklet transaction-manager="transactionManager">
<chunk reader="importExchangesFileItemReader" writer="importExchangesItemWriter"
commit-interval="${import.exchanges.commit.interval}" />
</tasklet>
</step>
<job id="importExchangesJob" restartable="true">
<step id="importExchangesStep.master">
<partition partitioner="importExchangesPartitioner"
handler="importExchangesPartitionHandler" />
</step>
</job>
Run Code Online (Sandbox Code Playgroud)
在将symfonyJob和importExchangesItemWriter的范围更改为scope ="step"之前,一切正常.我一改变了范围,就得到了
ERROR: org.springframework.batch.core.step.AbstractStep - Encountered an error executing step importExchangesStep in job importExchangesJob
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'scopedTarget.importExchangesItemWriter' defined in file [/home/vishal/install/sts-bundle/vfabric-tc-server-developer-2.9.6.RELEASE/base-instance/wtpwebapps/spring/WEB-INF/classes/META-INF/spring/batch/jobs/foundation/steps/import-exchanges.xml]: Initialization of bean failed; nested exception is org.springframework.beans.ConversionNotSupportedException: Failed …Run Code Online (Sandbox Code Playgroud) 我在spring spring item writer中使用spring amqp模板向rabbitmq队列添加消息.
public class AmqpAsynchRpcItemWriter<T> implements ItemWriter<T> {
protected String exchange;
protected String routingKey;
protected String queue;
protected String replyQueue;
protected RabbitTemplate template;
BlockingQueue<Object> blockingQueue;
public void onMessage(Object msgContent) {
try {
blockingQueue.put(msgContent);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
@Override
public void write(List<? extends T> items) throws Exception {
for (T item : items) {
Message message = MessageBuilder
.withBody(item.toString().getBytes())
.setContentType(MessageProperties.CONTENT_TYPE_TEXT_PLAIN)
.setReplyTo(this.replyQueue)
.setCorrelationId(item.toString().getBytes()).build();
template.send(this.exchange, this.routingKey, message);
}
for (T item : items) {
Object msg …Run Code Online (Sandbox Code Playgroud) $array1 = array (
'1' => A,
'2' => B,
'3' => C
);
$array2 = array (
'1' => A,
'4' => B,
'5' => D
);
$array3 = array (
'5' => A,
'6' => E,
'7' => D
);
$array4 = array (
'4' => A,
'7' => B,
'10' => C
);
Run Code Online (Sandbox Code Playgroud)
我想找出具有所有不同键的数组,而不是单个键应该在数组之间是通用的.
$array1 - $array3, $array1 - $array4是两种没有共用键的组合.算法的输出应该是这些组合.
我正在尝试使用spring amqp使用rabbitmq,下面是我的配置.
<rabbit:connection-factory id="rabbitConnectionFactory"
port="${rabbitmq.port}" host="${rabbitmq.host}" />
<rabbit:admin connection-factory="rabbitConnectionFactory" />
<rabbit:queue name="${rabbitmq.import.queue}" />
<rabbit:template id="importAmqpTemplate"
connection-factory="rabbitConnectionFactory" queue="${rabbitmq.import.queue}" />
<beans:bean id="importExchangeMessageListener"
class="com.stockopedia.batch.foundation.ImportMessageListener" />
<rabbit:listener-container
connection-factory="rabbitConnectionFactory" concurrency="5">
<rabbit:listener queues="${rabbitmq.import.queue}" ref="importMessageListener" />
</rabbit:listener-container>
Run Code Online (Sandbox Code Playgroud)
这是一个简单的Message Listener类,
import org.springframework.amqp.core.Message;
import org.springframework.amqp.core.MessageListener;
public class ImportMessageListener implements MessageListener {
@Override
public void onMessage(Message message) {
System.out.println("consumer output: " + message);
}
}
Run Code Online (Sandbox Code Playgroud)
这是生产者(春季批次的itemWriter),
public class ImportItemWriter<T> implements ItemWriter<T> {
private AmqpTemplate template;
public AmqpTemplate getTemplate() {
return template;
}
public void setTemplate(AmqpTemplate template) {
this.template = template; …Run Code Online (Sandbox Code Playgroud)