小编Gay*_*d.P的帖子

Symfony:我可以从Type/Form返回null吗?

我有一个Symfony的实体表格:

class MyType extends AbstractType
{

    /**
     * @param FormBuilderInterface $builder
     * @param array $options
     */
    public function buildForm(FormBuilderInterface $builder, array $options)
    {
       ...
    }

    /**
     * @param OptionsResolverInterface $resolver
     */
    public function setDefaultOptions(OptionsResolverInterface $resolver)
    {
        $resolver->setDefaults(array(
            'data_class' => 'LogicielBundle\Entity\FichierGroup',
            'intention' => $this->getName() . '_token'
        ));
    }
Run Code Online (Sandbox Code Playgroud)

但是在POST_SUBMIT事件中,我想返回null(没有实体).我测试了这个,但没有工作:

    $builder->addEventListener(FormEvents::POST_SUBMIT, function(FormEvent $event) {
        .... my condition ...
        $event->setData(null);
    });
Run Code Online (Sandbox Code Playgroud)

你能帮助我吗 ?谢谢 :)

php symfony-forms symfony

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

教义的find()和querybuilder()在PHPUnit测试中返回不同的结果

在我的PHPUnit测试方法中使用Doctrine和Symfony:

// Change username for user #1 (Sheriff Woody to Chuck Norris)
$form = $crawler->selectButton('Update')->form([
    'user[username]' => 'Chuck Norris',
]);
$client->submit($form);

// Find user #1
$user = $em->getRepository(User::class)->find(1);
dump($user); // Username = "Sheriff Woody"

$user = $em->createQueryBuilder()
        ->from(User::class, 'user')
        ->andWhere('user.id = :userId')
        ->setParameter('userId', 1)
        ->select('
            user
        ')
        ->getQuery()
        ->getOneOrNullResult()
    ;
dump($user); // Username = "Chuck Norris"
Run Code Online (Sandbox Code Playgroud)

为什么我的两种获取用户#1的方法返回不同的结果?

phpunit doctrine symfony

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

很难理解删除箭头函数的价值 () =>

当我在互联网上搜索react-native优化/最佳实践(特别是FlatLists通常贪婪的优化/最佳实践)时,我总是找到不要使用箭头函数的建议<Component onPress={() => ... }

\n

示例1: https ://reactnative.dev/docs/optimizing-flatlist-configuration#avoid-anonymous-function-on-renderitem :

\n
\n

将 renderItem 函数移出到 render 函数的外部,这样每次调用 render 函数时它就不会重新创建自己。(...)

\n
\n

示例 2: https: //blog.codemagic.io/improve-react-native-app-performance/

\n
\n

避免箭头函数:箭头函数是浪费重新渲染的常见罪魁祸首。不要\xe2\x80\x99t 在函数中使用箭头函数作为回调来渲染视图 (...)

\n
\n

示例 3: https: //medium.com/wix-engineering/dealing-with-performance-issues-in-react-native-b181d0012cfa

\n
\n

箭头函数是浪费重新渲染的另一个常见嫌疑点。不要在渲染函数中使用箭头函数作为回调(例如单击/点击)(...)

\n
\n

据我了解,建议不要使用箭头功能(尤其是在onPress按钮 和中FlatList),并尽可能将组件放在渲染之外。

\n

良好实践示例:

\n
const IndexScreen = () => {    \n  const onPress = () => console.log(\'PRESS, change state, etc...\')\n\n  return (\n    <>\n      <Button\n …
Run Code Online (Sandbox Code Playgroud)

javascript react-native

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

wkhtmltopdf 权限被拒绝

我已经安装了Wkhtmltopdf,当我执行他“/var/chroot/wkhtmltox-jessie-amd64:权限被拒绝”时出现此错误。我在 Google 中搜索,但我还没有找到该怎么做...剧目有这个权限“drwxr-xr-x root root”,我在网络服务器(apache)和 Symfony 中执行他。

错误 :

退出状态代码“126”表示出了问题:stderr:“sh:1:/var/chroot/wkhtmltox-jessie-amd64:权限被拒绝”stdout:“”

你能帮助我吗 ?

debian apache2 wkhtmltopdf symfony

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

Flex 容器的子容器超过了父容器

我在使用 React Native 和 flexbox 时遇到了一个奇怪的情况。

在这种情况下,我不明白为什么x按钮超出了它们的容器(cyan背景),尽管有 flexWrap。

在此输入图像描述

我希望x按钮返回到青色容器内的行,如标题(但按钮a b c d必须保持在右侧,这样效果很好)

https://codesandbox.io/s/lucid-dream-0q5yo?file=/src/App.js

class App extends Component {
  render() {
    return (
      <View style={styles.container}>
        <ListItem>
          <ListItem.Content style={styles.content}>
            <ListItem.Title>
              My title My title My title My title My title My title My title My
              title
            </ListItem.Title>
            <View style={styles.chart_container}>
              <View style={styles.chart}></View>
              <View style={styles.item_container}>
                <Button title="x" />
                <Button title="x" />
                <Button title="x" />
                <Button title="x" />
                <Button title="x" />
                <Button title="x" />
                <Button …
Run Code Online (Sandbox Code Playgroud)

css reactjs react-native

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

PHPUnit 返回“数据集 #0 无效。” 与数据提供者

这个简单的类返回

1) 警告为 App\Tests\Twig\GenerateTokenTest::testGenerateToken 指定的数据提供程序无效。数据集#0 无效。

class GenerateTokenTest extends TestCase
{
    /**
     * @dataProvider provideToken
     */
    public function testGenerateToken(int $length): void
    {
        $token = GenerateToken::generate($length);

        $this->assertTrue(true);
    }

    public function provideToken(): iterable
    {
        yield 8;
        yield 16;
        yield 29;
    }
}
Run Code Online (Sandbox Code Playgroud)

你知道为什么吗 ?

php phpunit

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

React Navigation:无法使用 createMaterialTopTabNavigator() 打开键盘

对于react-navigation/native (5.9.4)和 iOS(在 iPhone 8 上测试),我无法使用createMaterialBottomTabNavigator() (5.3.15)createMaterialTopTabNavigator() (5.3.15)

\n

当我使用这两个功能时,键盘不会在 iOS 上打开(或立即关闭)。这使得输入完全无法使用。

\n

在此输入图像描述

\n

我重新创建了一个非常简单的模型。使用 Snack Expo,在 Android 上,一切正常,在 iOS 上,键盘无法打开:

\n

https://snack.expo.io/xUeskyMm-

\n

在 中/Navigator/BottomTabNavigator,您可以更改取消注释/注释代码:

\n
const BottomTabNavigator = () => {\n  return (\n    <Tab.Navigator>\n      {/*\n      <Tab.Screen\n        name="GymTopTab"\n        component={GymTopTabNavigator}\n        options={{\n          tabBarLabel: "S\xc3\xa9ances",\n        }}\n      />\n      */}\n      <Tab.Screen\n        name="TrainingStack"\n        component={TrainingStackNavigator}\n        options={{\n          tabBarLabel: "S\xc3\xa9ances",\n        }}\n      />\n    </Tab.Navigator>\n  )\n}\n
Run Code Online (Sandbox Code Playgroud)\n

当我不使用时createMaterialTopTabNavigator()一切正常。createMaterialBottomTabNavigator()这就是为什么我认为当我和一起使用时会出现错误createMaterialTopTabNavigator()。但令我感到非常惊讶的是,如此基本的情况却造成了如此大的问题。

\n

react-native react-native-ios react-navigation

5
推荐指数
0
解决办法
270
查看次数

React Native Firebase Crashlitics:找不到 DSO libhermes.so

我刚刚设置了 Firebase Crashlitics,但看到了此错误:

致命异常:java.lang.UnsatisfiedLinkError找不到要加载的DSO:libhermes.so SoSource 0:com.facebook.soloader.ApkSoSource [root = /data/data/com.wololofit/lib-main flags = 1] SoSource 1 : com.facebook.soloader.DirectorySoSource[root = /data/app/~~DAa5QmzRi5oxpzp3KsccGQ==/com.wololofit-EEiD-rJZDFCbRjzPj4o-mQ==/lib/arm64 flags = 0] SoSource 2:com.facebook.soloader。 DirectorySoSource[root = /vendor/lib64 flags = 2] SoSource 3:com.facebook.soloader.DirectorySoSource[root = /system/lib64 flags = 2] 本机 lib 目录:/data/app/~~DAa5QmzRi5oxpzp3KsccGQ==/com. wololofit-EEiD-rJZDFCbRjzPj4o-mQ==/lib/arm64 结果:0

根据我的研究,此错误适用于某些不支持 Hermes 的设备:https://github.com/facebook/react-native/issues/29528

经常提出几种解决方案:

解决方案1.添加到android/app/build.gradle

implementation 'com.facebook.soloader:soloader:0.9.0+'
Run Code Online (Sandbox Code Playgroud)

解决方案2.添加:

if (enableHermes) {
    def hermesPath = "../../node_modules/hermes-engine/android/";
    debugImplementation files(hermesPath + "hermes-debug.aar")
    releaseImplementation files(hermesPath + "hermes-release.aar")
    qaImplementation files(hermesPath + "hermes-release.aar")
    stageImplementation files(hermesPath + "hermes-release.aar")
    prodImplementation files(hermesPath + …
Run Code Online (Sandbox Code Playgroud)

react-native

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

带有Flexbox和React Native的容器外文本

使用react native和flexbox,我不明白为什么文本在容器之外(橙色bakcground)?

<View style={styles.main_container}>
    <View style={styles.infos_container}>
        <View style={styles.info_item}>
            <Text style={styles.info_name}>
                Âge
            </Text>
            <Text style={styles.info_value}>
                18
            </Text>
        </View>
        <View style={styles.info_item}>
            <Text style={styles.info_name}>
                Médias publics
            </Text>
            <Text style={styles.info_value}>
                2
            </Text>
        </View>
    </View>
</View>

const styles = StyleSheet.create({
    infos_container: {
        backgroundColor: 'orange',
        flex: 1,
        flexDirection: 'row',
        flexWrap: 'wrap',
        padding: 5,
    },
    info_item: {
        margin: 5,
        alignItems: 'center',
    },
    info_name: {
        color: '#6c757d',
        fontSize: 11,
    },
    info_value: {
        color: '#343a40',
    },
})
Run Code Online (Sandbox Code Playgroud)

er

我只希望块styles.info_item是水平的橙色背景

flexbox reactjs react-native

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

在一行上重命名导入数组的键(很像解构)

在 javascript 和 React Native 中,我使用了一个 API 函数,它返回两个元素:resultserror.

import { findAll as forumFindAll } from '../../Api/ForumApi'

const IndexScreen = () => {
    const [results, error] = forumFindAll()
    ...
Run Code Online (Sandbox Code Playgroud)

我想重命名变量resultserror在一行上(很像解构)。

类似的东西(但我知道它不起作用):

 const [results as forumsResults, error as forumsError] = forumFindAll()
Run Code Online (Sandbox Code Playgroud)

javascript reactjs react-native

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