小编whi*_*ear的帖子

在FOSUserBundle上记录注册时间和登录时间

FOSUserbundle

我想在用户注册时记录User表上的createdAt,UpdateAt,loginAt等数据.

我在想的是我应该把它放在哪里.

我可以找到类似的参考

https://github.com/FriendsOfSymfony/FOSUserBundle/blob/master/Resources/doc/overriding_controllers.md

它说重写/src/Acme/UserBundle/Controller/RegistrationController.php

class RegistrationController extends BaseController
{
    public function registerAction()
    {
        $form = $this->container->get('fos_user.registration.form');
        $formHandler = $this->container->get('fos_user.registration.form.handler');
        $confirmationEnabled = $this->container->getParameter('fos_user.registration.confirmation.enabled');

        $process = $formHandler->process($confirmationEnabled);
        if ($process) {
            $user = $form->getData();

            /*****************************************************
             * Add new functionality (e.g. log the registration) *
             *****************************************************/
            $this->container->get('logger')->info(
                sprintf('New user registration: %s', $user)
            );

            if ($confirmationEnabled) {
                $this->container->get('session')->set('fos_user_send_confirmation_email/email', $user->getEmail());
                $route = 'fos_user_registration_check_email';
            } else {
                $this->authenticateUser($user);
                $route = 'fos_user_registration_confirmed';
            }

            $this->setFlash('fos_user_success', 'registration.flash.user_created');
            $url = $this->container->get('router')->generate($route);

            return new RedirectResponse($url);
        }

        return $this->container->get('templating')->renderResponse('FOSUserBundle:Registration:register.html.'.$this->getEngine(), array(
            'form' …
Run Code Online (Sandbox Code Playgroud)

symfony fosuserbundle

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

如何覆盖FOSUserBundle/Doctrine/UserManager.php

我正在将fileupload系统与fosuserbundle集成

我需要覆盖updateUser函数

/vendor/friendsofsymfony/user-bundle/FOS/UserBundle/Doctrine/UserManager.php
Run Code Online (Sandbox Code Playgroud)

我把这个文件复制到了

/ACME/UserBundle/Doctrine/UserManager.php
Run Code Online (Sandbox Code Playgroud)

但它不起作用.

这是我的临时/vendor/friendsofsymfony/user-bundle/FOS/UserBundle/Doctrine/UserManager.php

public function updateUser(UserInterface $user, $andFlush = true)
{
    $this->updateCanonicalFields($user);
    $this->updatePassword($user);

   //it works but it  should not be used here.
    $user->upload();
    //

    $this->objectManager->persist($user);
    if ($andFlush) {
        $this->objectManager->flush();
    }
}     
Run Code Online (Sandbox Code Playgroud)

symfony fosuserbundle

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

如何在制作包后使用xml而不是yml

Mybundle已经设置为使用services.yml

但我想使用services.xml.

所以我改变了DependacyInjection/MybundleExtension.php

#$loader->load('services.yml');     
$loader->load('services.xml');
Run Code Online (Sandbox Code Playgroud)

但它说

Unable to parse in      "\/Users\/whitebear\/httproot\/mutor\/src\/Acme\/MyBundle\/DependencyInjection\/..\/Resources\/config\/services.xml" at line 1 (near "").
Run Code Online (Sandbox Code Playgroud)

我的services.xml虽然在这里,我认为它是正确的(只是从其他网站复制和粘贴)

<services>
    <service id="acme.demobundle.calendar_listener" class="Acme\DemoBundle\EventListener\CalendarEventListener">
        <argument type="service" id="doctrine.orm.entity_manager" />
        <tag name="kernel.event_listener" event="calendar.load_events" method="loadEvents" />
    </service>

</services>
Run Code Online (Sandbox Code Playgroud)

还有其他地方我需要改变吗?

symfony

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

JavaScript返回值:<>是什么意思?

我正在尝试在此页面中使用API .

定义如下:

vline.Promise.<vline.Collection> getMessages([Number opt_limit])
Run Code Online (Sandbox Code Playgroud)

我想使用这个API的返回值,但是我不明白这<>意味着什么.我研究过JavaScript语言但我找不到任何线索.

我的脚本是:

vlinesession.getPerson(userId).done(function(person) {       
    person.postMessage(msg); //it works.
    var log = person.getMessages(20); //how can I parse 'log'?
}
Run Code Online (Sandbox Code Playgroud)

任何人都可以给我一些关于如何使用这个API的提示或一些示例?

javascript vline

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

如何使用 useState 钩子映射来自 API 的 JSON 响应

我的 API 返回像这样的复杂 json。

[ 
 {id: 1, pub_date: "2021-01-06T20:24:57.547721Z"},
 {id: 2, pub_date: "2021-01-06T20:24:57.547721Z"},
 {id: 3, pub_date: "2021-01-06T20:24:57.547721Z"}
]
Run Code Online (Sandbox Code Playgroud)

所以我的审判是这样的

const [result, setResult] = useState({});
const [result, setResult] = useState(null);
const [result, setResult] = useState([]);

useEffect(() => {
  axios.get('http://localhost:8000/api/results/')
  .then(res=>{
    console.log(res.data); // correctly received
    setResult(res.data); // error
    console.log(result); // nothing appears
  })
  .catch(err=>{console.log(err);});
}, []);
Run Code Online (Sandbox Code Playgroud)

但是对于任何尝试,它都会显示类似的错误

错误:对象作为 React 子对象无效(找到:带有keys的对象{id, pub_date})。如果您打算渲染子集合,请改用数组。


我有一些尝试和错误。

仍然有一些难以理解的行为。

  const [cnt,setCnt] = useState(0);

  useEffect(() => {
    axios.get('http://localhost:8000/api/results/')
  
    .then((res)=> {
 
      setCnt(2);
      console.log(cnt);//shows 0

    })
    .catch(err=>{console.log(err);});
  }, []); …
Run Code Online (Sandbox Code Playgroud)

javascript reactjs react-hooks

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

如何使用继承Controller类的类中的monolog

我正在使用monolog

在类DefaultController中扩展Controller

    $logger = $this->get('logger');
    $logger->info('Get Started');
Run Code Online (Sandbox Code Playgroud)

我可以从继承Controller类的类中调用this-> get('logger').但是我想使用其他类的记录器,例如/Entity/User.php我该如何制作呢?

我的参考是

http://symfony.com/doc/2.0/cookbook/logging/monolog.html

dependency-injection symfony

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

设置单选按钮的默认值

我的buildForm类如下所示.

    $builder->add('icon','entity',
            array(
            'class' => 'UserBundle:IconPics',
            'property' => 'label', // .. or whatever property the image location is stored.
            'expanded' => true,
            'multiple' => false,        
            'label' => 'form.icon', 'translation_domain' => 'FOSUserBundle',
             'query_builder' => function ($repository) {
                return $repository->createQueryBuilder('i')
                ->add('where', 'i.enabled = true');
             }
    ));
Run Code Online (Sandbox Code Playgroud)

如何设置此radiobutton的默认值?

根据Peter Bailey的回答

use Acme\UserBundle\Entity\IconPics;
//
$IconPics = new IconPics();
// howw can I select the target Icon?????
Run Code Online (Sandbox Code Playgroud)

symfony doctrine-orm

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

用 !在 JSX 中的 Reactjs 组件中

我想更改Material-UI Button组件。

<Button>
Run Code Online (Sandbox Code Playgroud)

<Button disabled>
Run Code Online (Sandbox Code Playgroud)

所以我的源代码是这样的,但它显示了 Parsing error: Unexpected token, expected "..."

<Button {!this.state.enClick ? "" : disabled }><Button>
Run Code Online (Sandbox Code Playgroud)

不在Button标签{!A ? B:C }作品中。

<Button>
{!this.state.enClick ? "OK":"No"}
</Button>
Run Code Online (Sandbox Code Playgroud)

为此目的的最佳做法是什么?

javascript reactjs

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

错误:无法使用“const char [34]”类型的左值初始化“const char”类型的返回对象

我是 g++ 的新手。

我正在尝试编译这个简单的代码。

然而却出现了这个错误。

错误:无法使用“const char [34]”类型的左值初始化“const char”类型的返回对象

#include <boost/python.hpp>

char const doYouDo( const char* jobs ){
    return "Hello, I am an embedded engineer.";
}

BOOST_PYTHON_MODULE( what ){
    boost::python::def( "doYouDo", doYouDo);
}
Run Code Online (Sandbox Code Playgroud)

我应该在哪里修复?

我的 g++ 编译命令在这里。

$g++ -fPIC -Wall -I/System/Volumes/Data/Users/whitebear/anaconda3/envs/aiwave/include/python3.6m/ -lboost_python -shared -o whatModule.so what.cpp
Run Code Online (Sandbox Code Playgroud)

c++

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

使用“aws ecs execute-command”处理“aws ecs list-tasks”JSON 输出?

例如执行此命令。

aws ecs list-tasks --cluster aic-prod
Run Code Online (Sandbox Code Playgroud)

然后它返回下面

{
    "taskArns": [
        "arn:aws:ecs:ap-northeast-1:678100228133:task/aic-prod-cn/ae340032378f4155bd2d0eb4ee60b5c7"
    ]
}
Run Code Online (Sandbox Code Playgroud)

然后使用ae340032378f4155bd2d0eb4ee60b5c7of return 语句执行下一个命令。

aws ecs execute-command --cluster aic-prod-cn --container AicDjangoContainer --interactive --command '/bin/bash' --task ae340032378f4155bd2d0eb4ee60b5c7
Run Code Online (Sandbox Code Playgroud)

我想用一句话或者shell脚本来做这件事情。是否可以?

我用谷歌搜索了正则表达式,但仍然不清楚。

 aws ecs list-tasks --cluster aic-prod | grep taskArns | (regular expression??)
Run Code Online (Sandbox Code Playgroud)

你能提供一些帮助吗?

linux bash shell amazon-web-services amazon-ecs

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