草庐IT

some_collection

全部标签

php - 拉维 5.1 : How to share a collection in all views?

我需要在所有View中共享一个集合。此集合包含网站新闻:$news=NewsStory::orderBy('created_at','desc')->paginate(5);我该怎么做? 最佳答案 可以分享ViewData所有View之间。只需将这一行添加到App\Providers\AppServiceProvider中的boot()方法:view()->share('news',NewsStory::orderBy('created_at','desc')->paginate(5));

php - 即使在包含 laravel Collective 之后,Laravel 5.1 Blade 也无法正常工作

composer.json{"name":"laravel/laravel","description":"TheLaravelFramework.","keywords":["framework","laravel"],"license":"MIT","type":"project","require":{"php":">=5.5.9","laravel/framework":"5.1.*","laravelcollective/html":"5.1.*"},"require-dev":{"fzaninotto/faker":"~1.4","mockery/mockery":"0.9

php - Symfony2,EntityManager::getRepository(命名空间\To\Some\Class::class 或 '**Bundle:Entity')

Symfony2文档说我应该使用别名快捷方式'ByBundle:myEntity'作为实体路径:$em->getRepository('ByBundle:myEntity');但是这个字符串文字没有用——没有重构,没有在IDE中快速自动重命名实体类。我使用魔术方法::class$em->getRepository(\ByBundle\Entity\myEntity::class);问题:我这样做对吗? 最佳答案 事实上,Symfony2核心团队正在使用::class方法来添加表单字段类型,例如:$builder->add('name

基于 PHP Memcache(d) 的 session : Should garbage collection be disabled?

当使用peclmemcached(或者我猜是memcache..)扩展时,是否应该通过将概率设置为0来禁用php的session垃圾收集(例如:session.gc_probability/session.gc_divisor)?由于以下原因,这似乎是合乎逻辑的:A)session过期时间很可能只是通过在存储的key上设置过期时间来简单地存储。EG:每个session都有其到期ttl,并在到期时被memcached简单地清除。B)要清除尚未被memcached本身清除的现有session,memcached扩展必须对存储在memcache守护进程中的所有数据进行完整转储,检查每个键以查

php - 如何使用 PHP 对数组进行排序,忽略 (Mr, Mrs) 或 Some 文章

使用名称对数组进行排序我有一个数组。array(0=>Mr.Bala,1=>Mr.Santhosh,2=>Mrs.Camel,3=>Mrs.Vinoth);仅根据姓名升序排列我的预期输出是array(0=>Mr.Bala,1=>Mrs.Camel,2=>Mr.Santhosh,3=>Mr.Vinoth,); 最佳答案 使用usort,取字符串的第二部分,按点分割,后加空格usort($a,function($i1,$i2){returnstrcmp(explode('.',$i1)[1],explode('.',$i2)[1]);}

php - 如何通过索引将项目添加到 Laravel Eloquent Collection 中?

我尝试了以下但它不起作用。$index=2;$collection->put($index,$item4);例如,如果$collection看起来像这样:$collection=[$item1,$item2,$item3];我想结束:$collection=[$item1,$item2,$item4,$item3]; 最佳答案 最简单的方法可能是拼接它,像这样:$collection->splice(2,0,[$item4]);集合通常支持与常规PHP数组相同的功能。在这种情况下,它是array_splice()在幕后使用的函数。通

php - Symfony 返回错误 : some parameters are missing. 请提供它们

我正在尝试在wamp服务器上安装symfony,我正在通过composer安装。我在cmd中尝试了以下命令$composercreate-projectsymfony/framework-standard-editionsym2以上命令在wamp上正确安装了symfony最新版本,但最后它返回错误或请求编辑某些东西。创建“app/config/parameters.yml”文件`我附上了cmd屏幕截图以供引用,任何人都可以指导我如何解决这个问题。在安装symfony之前,我还更新了composerphar。 最佳答案 这不是bug(

php - Count Doctrine 的 iterate() Collection Result

有一个QueryBuilder结果$query=$em->createQuery("SELECT....");通过iterate()方法获取它们http://doctrine-orm.readthedocs.org/en/2.0.x/reference/batch-processing.html$objects=$query->iterate();我现在可以foreach($objectsas$object){$object=$object[0];//dosomething..$object->getObjectId();...}但是...//aftertheiterate()call

php - 使用 Laravel Collection 获取重复值

我不想删除重复值,我想获取articles_id重复项并将它们的数量值相加,例如,这是我的收藏:Collection{#306▼#items:array:3[▼0=>CartLine{#294▼+quantity:2+article_id:1728+article_name:"TAZACERAMICA"}1=>CartLine{#296▼+parent_line_id:null+quantity:1+article_id:1728+article_name:"TAZACERAMICA"}2=>CartLine{#298▼+quantity:1+article_id:1378+artic

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)