我有一个实体订单,它将供应商保存在Arraycollection中.在我的控制器中,我想检查此arraycollection是否为空:
$suppliers = $order->getSuppliers();
Run Code Online (Sandbox Code Playgroud)
我试过了:
if(!($suppliers)) {}
if(empty($suppliers)) {}
Run Code Online (Sandbox Code Playgroud)
有任何想法吗?
在使用HTML 5输入字段选择.csv文件后,我尝试获取该文件的输入。因此,我使用了onFileChange方法和FileReader()。这是我使用的示例:http : //codepen.io/Atinux/pen/qOvawK/(除了我想读取文本输入,而不是图像文件)。
我的问题是,第一次尝试时得到的输入为空,但是第二次尝试时它却起作用。这是为什么?有任何想法吗?(我是javascript初学者;))
的HTML:
<form enctype="multipart/form-data">
<input type="file" @change="onFileChange">
</form>
Run Code Online (Sandbox Code Playgroud)
js:
new Vue({
el: '#app',
data: {
fileinput: ''
},
methods: {
onFileChange(e) {
var files = e.target.files || e.dataTransfer.files;
if (!files.length)
return;
this.createInput(files[0]);
},
createInput(file) {
var reader = new FileReader();
var vm = this;
reader.onload = (e) => {
vm.fileinput = reader.result;
}
reader.readAsText(file);
console.log(this.fileinput);
}
}
})
Run Code Online (Sandbox Code Playgroud) 我的实体之间有多对多的关系:PurchaseOrder和Supplier.当我想Supplier在我的Symfony项目中添加订单时,我总是会收到以下错误消息:
属性"供应商"在"Acme\AppBundle\Entity\PurchaseOrder"类中不公开.也许你应该创建方法"setSuppliers()"?
当我setSuppliers()在PurchaseOrder实体中自己创建一个函数时:
public function setSuppliers(\Acme\AppBundle\Entity\Supplier $suppliers )
{
$this->suppliers = $suppliers;
return $this;
}
Run Code Online (Sandbox Code Playgroud)
我收到此错误消息:
可捕获致命错误:传递给Doctrine\Common\Collections\ArrayCollection :: __ construct()的参数1必须是类型数组,给定对象,在/ var/www/symfony/vendor/doctrine/orm/lib/Doctrine/ORM中调用/UnitOfWork.php在第519行并在/var/www/symfony/vendor/doctrine/collections/lib/Doctrine/Common/Collections/ArrayCollection.php第47行中定义
有任何想法吗?
/**
* @Route("order/{id}/supplieradd", name="order_supplieradd")
* @Secure(roles="ROLE_ADMIN")
*/
public function newSupplierAction(Request $request, $id)
{
$purchaseOrder = $this->getDoctrine()
->getRepository('AcmeAppBundle:PurchaseOrder')
->find($id);
if (!$purchaseOrder) {
throw $this->createNotFoundException(
'No order found for id '.$id
);
}
$form = $this->createForm(new AddSupplierType(), $purchaseOrder);
// process the form on POST
if ($request->isMethod('POST')) {
$form->bind($request);
if ($form->isValid()) …Run Code Online (Sandbox Code Playgroud) 我找到了一个代码片段,并且不明白(*对象)后索引[1]和[0]的作用
对象:
Edge *edgea = new Edge(vertex_a,triangle);
Edge *edgeb = new Edge(vertex_b,triangle);
Run Code Online (Sandbox Code Playgroud)
电话:
Edge *edgea_opposite = getEdge((*edgea)[1],(*edgea)[0]);
Run Code Online (Sandbox Code Playgroud) symfony ×2
c++ ×1
doctrine-orm ×1
javascript ×1
mapping ×1
pointers ×1
setter ×1
symfony-2.2 ×1
vue.js ×1