草庐IT

Set集合

全部标签

php - 如何在集合 laravel 中添加新值?

我在以下循环中尝试添加新值:foreach($pro->sig()->get()as$key=>$sig){$sig->val=2;}当我打印$pro->sig()的输出时我没有新值$sig->val 最佳答案 如果您有一个集合,您可以使用push或put方法。放置示例:$collection=collect(['product_id'=>1,'name'=>'Desk']);$collection->put('test','test');$collection->all();输出将是:['product_id'=>1,'name'

php - Symfony2 表单集合 : How to remove entity from a collection?

我尝试从集合中删除实体,但它不起作用。我想我在某处有错误,但我不知道在哪里。这是我的updateAction中的代码:$em=$this->getDoctrine()->getEntityManager();$entity=newPerson();if(!$entity){throw$this->createNotFoundException('UnabletofindPersonentity.');}$editForm=$this->createForm(newPersonType(),$entity);$deleteForm=$this->createDeleteForm($id)

php - 此集合实例上不存在属性 [id]

这个问题在这里已经有了答案:Property[title]doesnotexistonthiscollectioninstance(8个答案)关闭去年。我正在尝试创建编辑页面,但此错误不断弹出糟糕,好像出了点问题。此集合实例上不存在属性[id]。到目前为止我做了什么这是我的路线Route::get('book/edit/{id}','BookController@edit')->name('admin.book.edit');Route::PATCH('book/edit/{id}','BookController@update')->name('admin.book.edit');这

php - 我应该使用 set_value() 来重新填充 CodeIgniter 中的表单吗

我的问题是我是否应该使用set_value()来重新填充表单。这么说似乎很奇怪,但我正在创建一个共享Controller功能和View,可用于添加新记录或编辑现有记录。这样做似乎很有意义,因为功能非常相似。因此,如果我们调用现有记录进行编辑,我会这样做:$data['fields']=$this->customer_model->get_customer($id);如果提交表单以保存记录,或者如果我们是第一次添加记录,则如果用户出错,表单有可能重新加载,所以我填充$data['fields']这个方式代替:$data['fields']=array('company'=>$this->

php - set_value 不适用于 Codeigniter 上的输入类型文件

我正在为我的项目使用HMVCCodeigniter模式。在我的项目中,我需要在输入字段类型为文件的表单上设置值。所以,我很感谢帮助我解决这个问题的他们。我的Controller是test.phpload->library('form_validation');$this->load->helper('url');$this->form_validation->set_rules('fname','FirstName','required|trim');$this->form_validation->set_rules('mname','MiddleName','required|tri

php - Laravel 5(.7) 用多重关系组织模型/集合

关闭。这个问题需要更多focused.它目前不接受答案。想改善这个问题吗?更新问题,使其仅关注一个问题editingthispost.2年前关闭。Improvethisquestion我有以下Eloquent查询,它大量使用了relationships在模型上,它有效。这里是:$trip=ModelLocale::where("lang",$lang)->where("slug",$slug)->where('mainmodel_id',$id)->with(['mainmodel'=>function($query)use($id){$query->where('id',$id)->

PHP memory_get_peak_usage 和 ini_set ('memory_limit' , '-1' )

我最近遇到了内存分配问题,所以我开始尝试使用ini_set('memory_limit',value);指令,尝试以增量方式输入值。现在,通过网络(和SO)搜索我发现我可以将-1作为value。所以,我做到了,现在脚本完全运行到最后没有中断(在我以前得到内存分配错误之前)。然而,我不明白的是,脚本文件末尾的这两行:$mem=memory_get_peak_usage(true);echo"Peakmem.usage:".round($mem/1024/10124,2)."MB";产生大约10.8MB,当我查看/var/log/messages时,我可以看到这一行:Nov2113:52:

php - 在构造函数中初始化集合有什么用

我在Symfony中使用Doctrine,实体生成器在实体的构造函数中初始化集合。例如:/***@varMyProject\MyBundle\Entity\Foo**@ORM\ManyToMany(targetEntity="MyProject\MyBundle\Entity\Foo")*/private$foos;publicfunction__construct(){$this->foos=new\Doctrine\Common\Collections\ArrayCollection();}我可以读入Doctrine'sbestpractices那...这样做是一个很好的做法。但问

php - Laravel 集合 mapWithKeys

我一直在尝试使用laravel的集合函数创建一个数组mapWithKeys,但我无法实现我所需要的。这是我的代码,$years=range(1900,date('Y'));returncollect($years)->mapWithKeys(function($value){return[$value=>$value];})->all();预期结果Array([1900]=>1900[1901]=>1901[1902]=>1902....[2017]=>2017)但是我得到的是Array([0]=>1900[1]=>1901[2]=>1902...[117]=>2017)

php - 为数据对象集合选择数据结构

我正在尝试设计一个PHP对象(将其称为Incident_Collection),该对象将包含其他对象的集合,每个对象都实现了一个Incident接口(interface)。incident_date;}}?>起初我想我只是让我的Incident_Collection实现IteratorAggregate并将事件对象存储在集合的数组属性中:collection);}publicfunctionsort(){//sortby$incident->when()valuesin$this->collection}/*also__get($var),__set($var,$value),add(