小编Squ*_*zic的帖子

symfony如何监听_switch_user?

我有一个应用程序,其中我有一个superadmin角色和具有不同权限的各种用户角色.我希望能够使用http://symfony.com/doc/current/book/security.html#impersonating-a-user上_switch_user显示的任何这些用户进行冒充.

但是,当我将查询添加到我的网址末尾时,它似乎没有做任何事情.我已经玩了很长时间了,似乎无法找到解决方案.我知道用户已登录ROLE_ALLOWED_TO_SWITCH,但我似乎无法弄清楚symfony是如何做到的.

我正在使用自定义身份验证提供程序,所以我认为它与此有关,但我不确定我需要关注什么.我可以发布所需的任何代码,但我真的不确定现在要发布什么.

symfony

5
推荐指数
1
解决办法
2159
查看次数

关于Haskell中函数的fmap

我正在尝试为函数实现fmap,并且无法弄清楚如何将"lift"应用于函数,而不是所有文档如何引用简单类型 Maybe

我想要实现的函数的类型是

fmapFunction :: (a -> b) -> (e -> a) -> (e -> b)
Run Code Online (Sandbox Code Playgroud)

有什么想法我应该怎么做?

haskell

4
推荐指数
1
解决办法
221
查看次数

Symfony 2将变量传递给表单类,以在表单中动态创建隐藏字段

我正在研究一种关于symfony 2框架的博客工具,其中一篇帖子可以有很多评论.我在各个实体的帖子和评论之间建立了一对多的关系.当帖子显示在主页上时,我想在其下面有一个评论表单,用户可以在其中发表评论.为了发表评论,我必须在postID的表单中传递一个隐藏字段,但我无法这样做.以下是我的所有代码..

控制器:

<?php

namespace Issh\MainBundle\Controller;

use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Symfony\Component\HttpFoundation\Response;
use Issh\MainBundle\Form\Post\CommentForm;
use Issh\MainBundle\Form\Post\PostForm;
use Issh\MainBundle\Entity\IsshPost;
use Issh\MainBundle\Entity\IsshComment;

class HomeController extends Controller
{

    public function indexAction()
    {
        return $this->render('IsshMainBundle:Home:index.html.php');
    }

    public function postAction()
    {
        $em = $this->get('doctrine')->getEntityManager();
        $request = $this->get('request');

        $post = new IsshPost();        
        $form = $this->createForm(new PostForm(), $post);

        if ('POST' == $request->getMethod()) 
        {        
            $form->bindRequest($request);           
            $post->setIsshUser($this->get('security.context')->getToken()->getUser());

            if ($form->isValid()) 
            {
                $em->persist($post);
                $em->flush();

                return $this->redirect($this->generateUrl('home'));
            }
            return $this->render('IsshMainBundle:Home:IsshPost.html.php', array(
                 'form'  =>  $form->createView()));   
        }
        else
        {
            $em = $this->getDoctrine()->getEntityManager();
            $posts = $em->getRepository('IsshMainBundle:IsshPost')->getLatestPosts();
            return …
Run Code Online (Sandbox Code Playgroud)

forms symfony

3
推荐指数
1
解决办法
9026
查看次数

反向关系ToManyField Tastypie

我有两个资源(Tastypie),其中一个有一个ToManyField字段:

class SongResource(ModelResource):

    class Meta:
        queryset = Song.objects.all()
        resource_name = 'song'
        authorization = Authorization()



class AlbumResource(ModelResource):
    songs = fields.ToManyField('core.api.SongResource', 'songs', full=True)
    class Meta:
        queryset = Album.objects.all()
        resource_name = 'album'
        authorization = Authorization()
Run Code Online (Sandbox Code Playgroud)

因此,当我访问我的PlaylistResource时,我看到如下内容:

http://127.0.0.1:8000/api/v1/playlist/1/?format=json 以下是我得到的回复:

{
"created_in": "2012-06-24T22:57:01+00:00",
"id": "1",
"number_of_plays": 0,
"playlist_slug": "my-first-playlist",
"playlist_title": "my first playlist",
"resource_uri": "/api/v1/playlist/1/",
"songs": [{
    "genre": "Progressive metal",
    "id": "2",
    "length": "04:19",
    "number_of_plays": 0,
    "price": 0.0,
    "resource_uri": "/api/v1/song/2/",
    "song_slug": "leyla-2008",
    "song_title": "Leyla",
    "song_url": "http://www.amazon.s3.com/prologue",
    "thumbnail": "http://almacosta.files.wordpress.com/2011/05/bob_marley.jpg?w=250",
    "year": 2008
}, {
    "genre": …
Run Code Online (Sandbox Code Playgroud)

django json tastypie

3
推荐指数
1
解决办法
3237
查看次数

仅保留列表中唯一项目的最有效方法?

所以我对Python比较陌生,试图弄清楚在列表中只保留唯一项目的最佳方法.我目前的实现涉及计数器,字典和列表推导,但我不确定什么可能更快.

这是我尝试过的一个例子:

l = ['a', 'b', 'a']
d = dict(Counter(l))
[key for key, val in d.items() if val == 1]
>>> ['b']
Run Code Online (Sandbox Code Playgroud)

此外,这只适用于字符串而不是整数,我不知道为什么.

python performance list

2
推荐指数
2
解决办法
3207
查看次数

如何在Haskell中fmap元组的第一个元素

我试图写一个像

mapFst :: Maybe (a, String) -> Maybe ([a], String)
mapFst (a,s) = (:) <$> (a,s) <*> [other fun with same type as mapFst] (a,s)
Run Code Online (Sandbox Code Playgroud)

在这里,我试图基于元组的第一个元素构建一个列表,但是我不确定如何继续。我可以针对非元组执行此操作,但是不确定如何fst在此构造中使用(如果我应该首先使用该功能)。

此函数将与另一个相同类型的接口,但处理输入的方式略有不同。我需要使用fmap和ap,因为元组位于Maybe容器内

haskell functor applicative

2
推荐指数
1
解决办法
1257
查看次数

Web.Authenticate.Facebook怎么了?

在以前版本的authenticate包中,有一些用于Facebook身份验证的东西.为什么在新版本中不存在?这与Facebook API改变的事实有关吗?

haskell facebook

0
推荐指数
1
解决办法
169
查看次数