小编Dhi*_*bbi的帖子

为什么我部署的 Symfony 应用程序无法加载 bundles.php 文件?

我有一个 Symfony Web 应用程序。我想将其部署到虚拟专用服务器。

我在Laravel Homestead Vagrant box中开发了该应用程序,并通过 Github 操作进行部署。

在我的本地计算机上,该应用程序在 Vagrant 环境中运行良好,但在将文件同步到实时服务器后,它给我一个错误屏幕。

警告:require(/var/www/thebedechkacase.com/src/config/bundles.php):无法打开流:没有这样的文件或目录

错误来自 Kernel.php 的第 20 行,如下所示

const CONFIG_EXTS = '.{php,xml,yaml,yml}';
public function registerBundles()
{
    $contents = require $this->getProjectDir().'/config/bundles.php';
    foreach ($contents as $class => $envs) {
        if ($envs[$this->environment] ?? $envs['all'] ?? false) {
            yield new $class();
        }
}
Run Code Online (Sandbox Code Playgroud)

我不明白的是,根据错误消息和上面的代码, 的输出解析$this->getProjectDir()/var/www/thebedechkacase.com/src/thebedechkacase.com是存储我的应用程序代码的文件夹),但bundles.php实际上位于/var/www/thebedechkacase.com/config/.

为什么 Symfony 认为 theprojectDir存在并且为什么不在根目录(又名 )中src查找?为什么这在我的开发环境中有效,但在实时服务器上却不起作用?configthebedechkacase.com/

附加信息:我正在尝试使用在 Github 操作中调用的 shell …

php deployment symfony devops

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

错误系统库:fopen:No such process

我开始使用这个库https://github.com/lexik/LexikJWTAuthenticationBundle 当我使用命令时php bin/console lexik:jwt:generate-keypair,控制台显示这个错误

在 GenerateKeyPairCommand.php 第 151 行中:

错误:02001003:系统库:fopen:没有这样的过程

我有 PHP 7.1 的 Symfony 5 并且 Openssl 正在运行。

php symfony lexikjwtauthbundle

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

如何从子表单获取 Symfony3 父表单的值?

我有一个带有嵌入表单的父表单。在嵌入(子)表单中,我希望创建一个下拉字段,其中包含从数据库查询的另一个实体的选项。作为查询的一部分,我需要引用父实体,但不确定如何从子表单类访问该父对象。

例如,父级是$subscriber实体。就我而言,父表单实际上不显示与订阅者相关的任何属性,仅允许您添加或删除子实体表单。每个子表单必须具有如上所述的字段,但选择需要限制为订阅者已经与之建立关系的值。

但这就是我的问题所在。如何$subscriber从子窗体中使用的代码访问下面的变量?:

$builder->add('otherEntity', EntityType::class, array(
    'class' => "AppBundle:YetAnotherEntity",
    'label' => "Other Entity",
    'query_builder' => $this->manager->getRepository("AppBundle:OtherEntity")->getOtherEntityBySubscriber($subscriber)
 ));
Run Code Online (Sandbox Code Playgroud)

它又在我的存储库中调用此函数:

public function getOtherEntityBySubscriber($subscriber)
{
    return $this->getEntityManager()
        ->createQuery(
            'SELECT o FROM AppBundle:OtherEntity o JOIN n.subscriberOtherEntity so WHERE o.subscriber = :subscriber'
        )
        ->setParameter("subscriber", $subscriber)
        ->getResult();
}
Run Code Online (Sandbox Code Playgroud)

在 jbafford 的建议之后:我尝试了您的第一个选项,但我的问题是我的父表单调用的类型CollectionType::class不是我的自定义类型...因为我计划制作一个可以添加多个子项目的表单。我无法将任何自定义选项传递给CollectionType. 我是否需要扩展CollectionType以创建能够接受额外选项的自己的类型?

我的父表单如下所示:

$builder->add('child', CollectionType::class, array(
  "entry_type" => ChildType::class,
  "allow_add" => true,
  "by_reference" => false,
  "allow_delete" => true)
);
Run Code Online (Sandbox Code Playgroud)

如果我将订阅者添加为上面的选项,我会收到一个错误,基本上说它不是有效的选项。我尝试让我的 ChildType 扩展 CollectionType 但我不认为这是我需要做的,并收到一条错误消息:

表单的视图数据应该是类 AppBundle\Entity\Child …

symfony-forms symfony

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

EasyAdmin 中的用户密码管理

我有 2 个问题/疑虑

  1. 当我编辑用户时,我并不总是需要更改用户的密码,我该如何更改?

  2. 如何在数据库中保存加密的密码,到目前为止,我只能以纯文本形式成功,而且我找到的所有说明都不是最新的和/或对我有帮助。

所有其他文件都是通过命令创建的,到目前为止没有变化。

我使用 Symfony 5.2.7 和 php 8.0.6

src/Controller/Admin/AdminCrudController.php

<?php

namespace App\Controller\Admin;

use App\Entity\Admin;
use EasyCorp\Bundle\EasyAdminBundle\Config\Crud;
use EasyCorp\Bundle\EasyAdminBundle\Controller\AbstractCrudController;
use EasyCorp\Bundle\EasyAdminBundle\Field\TextField;
use EasyCorp\Bundle\EasyAdminBundle\Field\TextareaField;
use EasyCorp\Bundle\EasyAdminBundle\Field\ArrayField;
use Symfony\Component\Form\Extension\Core\Type\PasswordType;

class AdminCrudController extends AbstractCrudController
{
    public static function getEntityFqcn(): string
    {
        return Admin::class;
    }

    public function configureCrud(Crud $crud): Crud
    {
        return $crud
            ->setEntityPermission('ROLE_ADMIN')
        ;
    }

    public function configureFields(string $pageName): iterable
    {
        yield TextField::new('username');
        yield TextField::new('password')
            ->hideOnIndex()
            ->setFormType(PasswordType::class)
        ;
        yield ArrayField::new('roles');
    }
}
Run Code Online (Sandbox Code Playgroud)
src/Entity/Admin.php

<?php

namespace App\Entity;

use App\Repository\AdminRepository;
use Doctrine\ORM\Mapping …
Run Code Online (Sandbox Code Playgroud)

php symfony symfony-security

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

FXML 文件中的 For 循环 || 如何将数据从控制器发送到 fxml 文件?

所以我正在开发一个 javaFX 应用程序,我想<ImageView>使用 for 循环创建多个!

是否可以在 .fxml 文件中创建 for/foreach 循环?

如果是,那又如何?

另外我还有一个问题!如何将数据从控制器发送到 sample.fxml 文件?例如,我想将表格表单 controller.java 发送到 sample.fxml 文件并使用该 table+for 循环<ImageView>在 fxml 文件中制作!

注意:我使用 fxml 来显示图像,因为我将这些图像用作按钮。

这是 sample.fxml 的代码:

<?import javafx.scene.layout.GridPane?>
<?import javafx.scene.image.ImageView?>
<?import javafx.scene.image.Image?>
<GridPane fx:controller="sample.Controller"
          xmlns:fx="http://javafx.com/fxml" alignment="center" hgap="10" vgap="10">


    <ImageView fitHeight="120" fitWidth="120" fx:id="panda" GridPane.columnIndex="0" GridPane.rowIndex="0" onMousePressed="#mousePressed">
        <image>
            <Image  url="@pics/panda.png">

            </Image>
        </image>
    </ImageView>

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

这是 Controller.java 的代码:

package sample;

import javafx.scene.input.MouseEvent;
import javafx.scene.media.AudioClip;

public class Controller {

    public void play_audio()
    {
        AudioClip sound = new AudioClip(this.getClass().getResource("voices/panda.mp3").toString()); …
Run Code Online (Sandbox Code Playgroud)

java javafx fxml

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

React-i18next addResourceBundle 不是一个函数

我正在使用 React-i18next 来国际化我的 React 应用程序。当我尝试addResourceBundle对每个模块的配置文件进行操作时,它会抛出此错误:

TypeError: i18next__WEBPACK_IMPORTED_MODULE_0__.default.addResourceBundle 不是函数

因此,我i18next.init之前添加了命令addResourceBundle。然后它可以工作,但显示下面的警告并重置先前选择的区域设置。

i18next: init: i18next 已经初始化。你应该只调用一次 init !

这是我的i18n.tsx文件

import i18n from 'i18next'
import Backend from 'i18next-http-backend'
import LanguageDetector from 'i18next-browser-languagedetector'
import { initReactI18next } from 'react-i18next'

i18n
 .use(Backend)
 .use(LanguageDetector)
 .use (initReactI18next)
 .init({
   fallbackLng: 'en',
   debug: true,
   detection: {
    order: ['queryString', 'cookie'],
    cache: ['cookie']
  },
  interpolation: {
    escapeValue: false
  },
  react: {
    wait: true,
    useSuspense: false,
 }
})

export default i18n;
Run Code Online (Sandbox Code Playgroud)

这是我的模块的配置文件

import i18next from …
Run Code Online (Sandbox Code Playgroud)

internationalization i18next reactjs

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

如何更改身份验证错误消息?

当用户尝试使用错误的用户名/密码登录时,会出现错误消息“凭据无效”!

如何更改getLastAuthenticationError()错误消息!

例如!而不是“无效凭据”,我希望它是“错误消息 123”

控制器代码:

/**
 * @Route("/login",name="security_login")
 */
public function login(AuthenticationUtils  $authenticationUtils)
{
     // get the login error if there is one
$error = $authenticationUtils->getLastAuthenticationError();


// last username entered by the user
$lastUsername = $authenticationUtils->getLastUsername();

    return $this->render('123/login.html.twig',[
        'lastUsername'=>$lastUsername,
        'error' => $error]);
}
Run Code Online (Sandbox Code Playgroud)

安全代码.yaml

security:
    encoders:
        App\Entity\User:
            algorithm: bcrypt

    # https://symfony.com/doc/current/security.html#where-do-users-come-from-user-providers
    providers:
        in_memory: { memory: null }
        in_database:
            entity: 
                class: App\Entity\User  
                property: username
    firewalls:
        dev:
            pattern: ^/(_(profiler|wdt)|css|images|js)/
            security: false
        main:
            anonymous: lazy
            provider: in_database
            form_login: 
                login_path: security_login
                check_path: …
Run Code Online (Sandbox Code Playgroud)

php authentication symfony twig

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

从网页中提取reCaptcha,通过cURL在外部完成,然后返回结果到查看页面

我正在创建一个供个人使用的网络抓取工具,它根据我的个人输入抓取汽车经销商网站,但我尝试从被重定向验证码页面阻止的几个网站收集数据。我正在用 curl 抓取的当前站点返回此 HTML

<html>
   <head>
      <title>You have been blocked</title>
      <style>#cmsg{animation: A 1.5s;}@keyframes A{0%{opacity:0;}99%{opacity:0;}100%{opacity:1;}}</style>
   </head>
   <body style="margin:0">
      <p id="cmsg">Please enable JS and disable any ad blocker</p>
      <script>
            var dd={'cid':'AHrlqAAAAAMA1gZrYHNP4MIAAYhtzg==','hsh':'C0705ACD75EBF650A07FF8291D3528','t':'fe','host':'geo.captcha-delivery.com'}
      </script>
      <script src="https://ct.captcha-delivery.com/c.js"></script>
   </body>
</html>
Run Code Online (Sandbox Code Playgroud)

我正在使用它来抓取页面:

<?php

function web_scrape($url)
{
    $ch = curl_init();
    $imei = "013977000272744";

    curl_setopt($ch, CURLOPT_URL, $url);
    curl_setopt($ch, CURLOPT_POST, 1);
    curl_setopt($ch, CURLOPT_VERBOSE, 1);
    curl_setopt($ch, CURLOPT_COOKIE, '_ym_uid=1460051101134309035;  _ym_isad=1; cxx=80115415b122e7c81172a0c0ca1bde40; _ym_visorc_20293771=w');
    curl_setopt($ch, CURLOPT_POSTFIELDS, array(
        'imei' => $imei,
    ));

    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);

    $server_output = curl_exec($ch);
    return $server_output;

    curl_close($ch);

}
echo web_scrape($url);

?> …
Run Code Online (Sandbox Code Playgroud)

html php curl recaptcha web-scraping

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

材质 UI 材质表 TablePagination 问题。(反应)

我正在使用material-table. 在TablePagination不工作。它在控制台中引发错误。

我尝试按照文档安装软件包。

https://material-table.com/#/docs/install

npm install material-table --save
npm install @material-ui/core --save
Run Code Online (Sandbox Code Playgroud)

我得到这个错误:

Material-UI:caption提供给 classes 道具的键未在 ForwardRef(TablePagination) 中实现。您只能覆盖以下其中一项:root,toolbar,spacer,selectLabel,selectRoot,select,selectIcon,input,menuItem,displayedRows,actions。

警告:失败的道具类型:道具onPageChange在 中标记为必需ForwardRef(TablePagination),但其值为 undefined

警告:未知的事件处理程序属性onChangePage。它将被忽略。

警告:未知的事件处理程序属性onChangeRowsPerPage。它将被忽略。

版本:

"@material-ui/core": "^5.0.0-alpha.24",
"material-table": "^1.69.2",
Run Code Online (Sandbox Code Playgroud)

如果我尝试分页,它会在控制台中引发错误。

未捕获的类型错误:_this.props.onChangePage 不是函数

示例代码:

 <MaterialTable
  icons={tableIcons}
  columns={columns}
  data={editable}
  title="Orders"
  localization={{
    toolbar: {
      searchPlaceholder: 'Filter',
      searchTooltip: 'filters the given text'
    },
    header: {
      actions: 'Actions'
    }
  }}
  actions={[
    {
      icon: 'save',
      tooltip: 'Save User',
      onClick: (event, rowData) => …
Run Code Online (Sandbox Code Playgroud)

reactjs material-ui material-table

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

Symfony Doctrine 预期已知函数,得到“JSON_GET_TEXT”

我正在尝试使用DoctrineJsonFunctions来过滤用户表的角色列。

我已按照文档进行操作并寻求帮助,但找不到解决我的问题的方法。

我已经DoctrineJsonFunctions正确安装了。

UserRepository我在我的函数中创建了一个函数

public function findByRole(string $role)
    {
        $em = $this->getEntityManager();
        $qb = $em->createQueryBuilder();

        $qb
            ->select('u')
            ->from('App:User', 'u')
            ->where("JSON_GET_TEXT(user.roles, 'role') = :role")
            ->setParameter('role', $role)
            ->getQuery()
            ->getResult();
    }
Run Code Online (Sandbox Code Playgroud)

但我遇到了这个错误:

预期的已知函数,得到“JSON_GET_TEXT”

有谁知道为什么并可以帮助我解决它?

php doctrine symfony doctrine-orm

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

Lexik JWT 身份验证问题“凭据无效”

我是 symfony 的新手,我正在使用 LexikJWTAuthenticationBundle 进行授权。我正在使用 symfony 6.0.2 和 2.14 lexic 版本。我正在使用 Postgresql 12.9。我的 security.yaml:

security:
    enable_authenticator_manager: true
    # https://symfony.com/doc/current/security.html#registering-the-user-hashing-passwords
    password_hashers:
        Symfony\Component\Security\Core\User\PasswordAuthenticatedUserInterface: 'auto'
        App\Entity\User:
            algorithm: auto

    # https://symfony.com/doc/current/security.html#loading-the-user-the-user-provider
    providers:
        # used to reload user from session & other features (e.g. switch_user)
        app_user_provider:
            entity:
                class: App\Entity\User
                property: email
    firewalls:
        login:
            pattern: ^/api/login
            stateless: true
            json_login:
                check_path: /api/login_check
                success_handler: lexik_jwt_authentication.handler.authentication_success
                failure_handler: lexik_jwt_authentication.handler.authentication_failure

        api:
            pattern:   ^/api
            stateless: true
            jwt: ~
        main:
            lazy: true
            provider: app_user_provider

        dev:
            pattern: ^/(_(profiler|wdt)|css|images|js)/
            security: false


            # activate different ways …
Run Code Online (Sandbox Code Playgroud)

php symfony symfony-security lexikjwtauthbundle

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

如何在命名空间 App\Controller 中声明一个新函数?

我编写了将生日日期转换为年龄的那些代码行。

我将在许多控制器和许多路由功能中使用此代码!所以我决定把它放在一个函数中,然后调用calculate_age().

我的问题是我怎么可以声明函数或任何功能 一旦里面的namespace App\Controller;?所以我可以在所有控制器中使用它。

功能代码:

public function calculate_age($birthday): ?int
{
    $current_date = date('d-m-Y', time());
    $info         = explode(' ', $birthday);
    $months       = ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'];
    $numbers      = ['01', '02', '03', '04', '05', '06', '07', '08', '09', '10', '11', '12'];
    $i            = 0;
    for ($i = 0; $i <= 11; ++$i) {
        if ($info[2] == $months[$i]) {
            $info[2] = $numbers[$i];
        }
    }
    $all = $info[1].'-'.$info[2].'-'.$info[3];

    $difference = …
Run Code Online (Sandbox Code Playgroud)

php namespaces declaration function symfony

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

Symfony 4:choiceType 未正确显示 choice_value

我是 Symfony 的新手,我想使用choiceType.

所以我将这段代码添加到buildForm方法中:

$builder->add('applications', ChoiceType::class, [
  'choices' => [
    '-- Choisir --' => NULL,
    'Admin' => '2',
    'Super' => '1',
    'visiteur' => '10',
    'admin local' => '98',
    'partenaire gestionnaire' => '16',
    'admin national' => '15',
    'soutien' => '11',
    'exploitant' => '12',
    'moe' => '99',
  ]
]);
Run Code Online (Sandbox Code Playgroud)

但是当我检查 HTML 代码时,我没有正确的数字:

<select id="user_applications" name="user[applications]" class="form-control">
  <option value="0" selected="selected">-- Choisir --</option>
  <option value="1">Admin</option>
  <option value="2">Super</option>
  <option value="3">visiteur</option>
  <option value="4">admin local</option>
  <option value="5">partenaire gestionnaire</option>
  <option value="6">admin national</option>
  <option value="7">soutien</option> …
Run Code Online (Sandbox Code Playgroud)

php symfony-forms symfony symfony4

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