我目前在一个地方,我需要在foreach循环中创建或更新实体.
所以我正在做以下(短代码):
foreach ($dataset as $data) {
$entity = new Entity();
// ---- Some setting operations on the entity
$em->persist($entity);
}
$em->flush();
Run Code Online (Sandbox Code Playgroud)
我期待的是Doctrine管理实体,然后用一个语句将实体插入表中.
但它发生了,Doctrine为每个创建的实体创建了一个语句.由于$ dataset数组可能相当大(创建了很多实体),我想把它打包成一个语句.
我怎样才能做到这一点?
是否可以验证依赖于同一类的另一个属性的模型类的属性?
例如,我有这个类:
class Conference
{
/** $startDate datetime */
protected $startDate;
/** $endDate datetime */
protected $endDate;
}
Run Code Online (Sandbox Code Playgroud)
我希望Symfony 2.0验证,$startDate必须在之后$endDate.
这可能是注释还是我必须手动执行此操作?
我正在研究基于锌的闪存应用程序的原生扩展,我需要将a转换const char*为a wstring.
这是我的代码:
mdmVariant_t* appendHexDataToFile(const zinc4CallInfo_t *pCallInfo, int paramCount, mdmVariant_t **params) {
if(paramCount >= 2) {
const char *file = mdmVariantGetString(params[0]);
const char *data = mdmVariantGetString(params[1]);
return mdmVariantNewInt(native.AppendHexDataToFile(file, data));
}
else {
return mdmVariantNewBoolean(FALSE);
}
}
Run Code Online (Sandbox Code Playgroud)
但native.AppendHexDataToFile()需要两个wstring.我对C++并不是很擅长,我认为所有这些不同的字符串类型都令人困惑,我在网上找不到有用的东西.所以我问你们这是怎么做的.
编辑:字符串是UTF-8,我使用的是OSX和Windows XP/Vista/7
我使用webpack并定位它的构建输出node-webkit.我想要求mongoose我的项目中的模块连接到mongodb,但是当我尝试打包项目时它总是会出现一些错误:
WARNING in ./~/mongoose/~/mongodb/~/mongodb-core/~/bson/~/bson-ext/ext/index.js
Module not found: Error: Cannot resolve 'file' or 'directory' ./win32/x64/bson in /Users/Johannes/Documents/Development/holmes/node_modules/mongoose/node_modules/mongodb/node_modules/mongodb-core/node_modules/bson/node_modules/bson-ext/ext
@ ./~/mongoose/~/mongodb/~/mongodb-core/~/bson/~/bson-ext/ext/index.js 6:10-37
WARNING in ./~/mongoose/~/mongodb/~/mongodb-core/~/bson/~/bson-ext/ext/index.js
Module not found: Error: Cannot resolve 'file' or 'directory' ./win32/ia32/bson in /Users/Johannes/Documents/Development/holmes/node_modules/mongoose/node_modules/mongodb/node_modules/mongodb-core/node_modules/bson/node_modules/bson-ext/ext
@ ./~/mongoose/~/mongodb/~/mongodb-core/~/bson/~/bson-ext/ext/index.js 8:10-38
WARNING in ./~/mongoose/~/mongodb/~/mongodb-core/~/bson/~/bson-ext/ext/index.js
Module not found: Error: Cannot resolve 'file' or 'directory' ../build/Release/bson in /Users/Johannes/Documents/Development/holmes/node_modules/mongoose/node_modules/mongodb/node_modules/mongodb-core/node_modules/bson/node_modules/bson-ext/ext
@ ./~/mongoose/~/mongodb/~/mongodb-core/~/bson/~/bson-ext/ext/index.js 10:10-42 15:9-41
ERROR in ./~/mongoose/~/mongodb/~/mongodb-core/~/kerberos/lib/kerberos.js
Module not found: Error: Cannot resolve 'file' or 'directory' ../build/Release/kerberos in /Users/Johannes/Documents/Development/holmes/node_modules/mongoose/node_modules/mongodb/node_modules/mongodb-core/node_modules/kerberos/lib
@ ./~/mongoose/~/mongodb/~/mongodb-core/~/kerberos/lib/kerberos.js 1:15-51
ERROR in …Run Code Online (Sandbox Code Playgroud) 我有一个这样的界面:
export interface Campaign {
id: string
orders?: number
avgOrderValue?: number
optionalAttributes: string[]
attributeValues: {
optionalAttributes: CampaignAttribute[]
mandatoryAttributes: CampaignAttribute[]
values?: { [key: string]: unknown }
}
created: number
lastUpdated: number
}
Run Code Online (Sandbox Code Playgroud)
我想为我的表单创建一个类型,需要在界面中省略attributeValues.optionalAttributes和。attributeValues.mandatoryAttributes
我在想也许 Typescript 可以做这样的事情:
export type CampaignFormValues = Omit<Campaign, 'attributeValues.mandatoryAttributes'>
Run Code Online (Sandbox Code Playgroud)
但这行不通。
我使用了这个问题的答案:Deep Omit with typescript 但这个答案只是深度省略了每个匹配的键,所以像这样使用它:
export type CampaignFormValues = Omit<Campaign, 'optionalAttributes'>
Run Code Online (Sandbox Code Playgroud)
还会删除optionalAttributes我想保留的根级别。
有没有办法用 Typescript 进行嵌套省略?
我是第一次尝试webpack并使用本教程开始并包含react.js.
完成步骤并安装style和css模块后,我不断收到错误,即css模块没有返回函数.
这是我的index.jsx:
/** @jsx React.DOM */
'use strict';
require('../css/normalize.css');
var React = require('react');
var Hello = require('./Test/Hello');
React.render(<Hello />, document.getElementById('content'));
Run Code Online (Sandbox Code Playgroud)
和我的webpack配置文件:
module.exports = {
entry: './ui/src/index.jsx',
output: {
path: __dirname + '/build-ui',
filename: 'app.js', //this is the default name, so you can skip it
//at this directory our bundle file will be available
//make sure port 8090 is used when launching webpack-dev-server
publicPath: 'http://localhost:8090/assets'
},
module: {
loaders: [
{
//tell webpack to …Run Code Online (Sandbox Code Playgroud) 是否可以将Handlebars.js与Backbone.Marionette扩展一起使用而无需重新实现Views渲染功能?似乎Marionette依赖于你使用带有下划线模板引擎的Backbone.js的约定.但我真的很喜欢车把方法,所以我问我是否可以使用车把的木偶高级工具.
我创建了一个这样的自定义表单类型:
class PositioningFlashType extends AbstractType
{
public function setDefaultOptions(OptionsResolverInterface $resolver)
{
$resolver->setDefaults(array(
'game' => new Game()
));
}
public function getParent()
{
return 'form';
}
/**
* Returns the name of this type.
*
* @return string The name of this type
*/
public function getName()
{
return 'positioning_flash';
}
}
Run Code Online (Sandbox Code Playgroud)
在另一种form(GameType)类型中,我使用它:
$builder
->add('flash', new PositioningFlashType(), array(
'mapped' => false,
'game' => $options['game']
))
Run Code Online (Sandbox Code Playgroud)
在控制器内部我想创建整个表单:
private function createEditForm(Game $entity)
{
$form = $this->createForm(new GameType(), $entity, array(
'action' => …Run Code Online (Sandbox Code Playgroud) 我想登录与通常的dev.log或prod.log不同的文件
我知道这可以用不同的通道完成,我在几个服务中使用它,但我不太清楚在控制器中切换Monolog通道.
在服务中,您只需通过tags服务定义中的属性定义通道,但是如何在控制器中执行此操作,或者在特定操作中更好?
我知道可能的解决方案是:Symfony 2:登录到特定文件
但是,为登录自定义文件定义两个新服务似乎有些过分.
我花了半个小时,但我还没有找到解决方案.
下面是一个数组示例:
array(14) {
["label_text"]=> string(10) "Label text"
["e-mail"]=> string(6) "E-Mail"
["company"]=> string(7) "Company"
["last_name"]=> string(9) "Last name"
["first_name"]=> string(10) "First name"
}
Run Code Online (Sandbox Code Playgroud)
我想要做的只是反转元素,结果如下:
array(14) {
["first_name"]=> string(10) "First name"
["last_name"]=> string(9) "Last name"
["company"]=> string(7) "Company"
["e-mail"]=> string(6) "E-Mail"
["label_text"]=> string(10) "Label text"
}
Run Code Online (Sandbox Code Playgroud)
必须有一个本机的PHP,但我认为我是盲人.我只是不知道使用哪个功能.
任何帮助赞赏!
symfony ×3
php ×2
webpack ×2
arrays ×1
backbone.js ×1
c++ ×1
doctrine-orm ×1
javascript ×1
logging ×1
marionette ×1
mongoose ×1
monolog ×1
node-webkit ×1
node.js ×1
symfony-2.1 ×1
symfony-2.4 ×1
twig ×1
typescript ×1
validation ×1