小编gp_*_*ver的帖子

创建包后Symfony3 ClassNotFoundException

我想在Symfony开始一个新的3.3项目并像往常一样开始:

1.)创建新项目: symfony new ArtProject

2.)创建一个新的Bundle :( php app/console generate:bundlePaul/ArtBundle,yml,src /)

然后我运行本地服务器,当我打开127.0.0.1:8000时,我得到了这个美丽的信息:

(1/1)ClassNotFoundException

尝试从命名空间"Paul\ArtBundle"加载类"PaulArtBundle".您是否忘记了另一个命名空间的"use"语句?在AppKernel.php中(第19行)

这很奇怪,我还没弄清楚到目前为止发生这种情况的原因.在创建Bundle之前,没有错误; 我看到了symfony的典型起始.

public function registerBundles()
{
    $bundles = [
        new Symfony\Bundle\FrameworkBundle\FrameworkBundle(),
        ......
        new Sensio\Bundle\FrameworkExtraBundle\SensioFrameworkExtraBundle(),
        new AppBundle\AppBundle(),
        new Paul\ArtBundle\PaulArtBundle(),
    ];
}
Run Code Online (Sandbox Code Playgroud)
<?php

namespace Paul\ArtBundle;

use Symfony\Component\HttpKernel\Bundle\Bundle;

class PaulArtBundle extends Bundle
{
}
Run Code Online (Sandbox Code Playgroud)

有什么想法吗?我没有更改任何东西,我只运行这些命令.

php exception symfony

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

Zend Framework 2 Doctrine 2一对多复选框保湿

我有一个ManyToMany我闯入OneToManyManyToOne关系.我想构建一个具有复选框而不是集合的表单,我正在使用'DoctrineObject'保湿器,但它不起作用,我不知道出了什么问题.

我从我的代码中删除了所有其他不相关的字段.

角色实体:

/**
 * @orm\Entity
 * @orm\Table(name="roles")
 */
class RolesEntity extends HemisEntity {
    /**
     * @orm\Id
     * @orm\Column(type="integer");
     * @ORM\GeneratedValue(strategy="IDENTITY")
     */
    protected $id;

    /**
     * @orm\Column(name="role_code",type="string")
     */
    protected $roleCode;

    /**
     * @orm\OneToMany(targetEntity="RolesPermissionsEntity", mappedBy="role", cascade={"persist"})
     */
    protected $rolePermissions;

    public function __construct()
    {
        $this->rolePermissions = new ArrayCollection();
    }

    public function setRolePermissions($rolePermissions)
    {
        $this->rolePermissions = $rolePermissions;
        return $this;
    }

    public function addRolePermissions(Collection $rolePermissions)
    {
        foreach ($rolePermissions as $rolePermission) {
            $rolePermission->setRole($this);
            $this->rolePermissions->add($rolePermission);
        }
    }

    public function …
Run Code Online (Sandbox Code Playgroud)

doctrine-orm zend-framework2 zend-form2

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

这种情况应该如何流动?(根据所选的付款方式,在哪里放置代码来处理付款?)

我有一个多步骤表单供用户在会议中注册,所有步骤都在同一registration.blade.php页面,在步骤1和步骤2完成ajax请求以验证表单字段.

步骤是:

  • Step1是收集一些关于用户的信息(名称和锡号)
  • 第2步是收取付款方式(信用卡或参考)
  • 第3步是付款
  • 步骤4显示成功消息(此步骤仅在使用信用卡成功付款后显示,参考付款方式此步骤不显示,使用参考付款方式仅显示步骤1,2和3)

我怀疑是在第2步和第3步之间.

如果执行下面的代码需要所选的付款方式参考,那么会生成一些付款参考,然后在步骤3中向用户提供该参考.当用户付款时,系统会收到通知并应插入付款表中price,payment_method_id,registration_idstatus(付费).

使用参考资料处理付款的代码:

    public function ReferencesCharge(Request $request)
        {
           $payment_info = [
        'name' => "user name",
        'email' => 'user email',
        'value' => 'registration total price',
        'id' => 'registration id',
    ];

    $newPayment = new Payment($payment_info);
    $reference = $newPayment->gererateReferences();

    //$reference returns an array with necessary codes to present to the user so he can pay

    // after generate references …
Run Code Online (Sandbox Code Playgroud)

php jquery laravel

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

如何修复此错误 Symfony\Component\Routing\Exception\RouteNotFoundException:未定义路由 [登录]。在 Laravel 8 中?

我有一个控制器,其中包含三个功能(注册、登录、忘记密码)。对于登录和注册,它工作正常,但是当我尝试在邮递员中使用 API 时,我收到错误,之前我使用单独的控制器来执行忘记密码()功能当时它工作正常,现在我将该控制器移至 USerController 我得到 500 个内部服务器,请帮我解决这个问题.. UserController.php

<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use Symfony\Component\HttpFoundation\Response;
use App\Models\User;
use Tymon\JWTAuth\Facades\JWTAuth;
use Tymon\JWTAuth\Exceptions\JWTException;
use App\Models\PasswordReset;
use App\Notifications\ResetPasswordNotification;


class UserController extends Controller
{
    public function __construct() {
        $this->middleware('auth:api', ['except' => ['login', 'register']]);
    }
    public function register(Request $request)
    {
        $this->validate($request, [
            'fullName'=>'required|string|between:3,15',
            'email'=>'required|email|unique:users',
            'password'=>'required|regex:/^(?=.*?[A-Z])(?=.*?[a-z])(?=.*?[0-9])(?=.*?[#?!@$%^&*-]).{6,}$/',
            'mobile'=>'required|digits:10'
            ]);
        $user = new User([
            'fullName'=> $request->input('fullName'),
            'email'=> $request->input('email'),
            'password'=> bcrypt($request->input('password')),
            'mobile'=>$request->input('mobile')           
        ]);
        $user->save();
        // User::create($request->getAttributes())->sendEmailVericationNotification();
        return response()->json(['message'=>'Successfully Created user'],201);
    }

    public function login(Request $request)
    {
        $this->validate($request, [
            'email' …
Run Code Online (Sandbox Code Playgroud)

php laravel laravel-8

13
推荐指数
3
解决办法
7万
查看次数

如何使用Symfony表达式语言在@Security批注中使用类常量?

我正在使用Symfony 3,我已经创建了一个自定义的Voter类.

我想使用SensioFrameworkExtraBundle @Security标签访问它.

它有点工作.

如果我执行以下操作,它将完美运行:

 /**
 * @Rest\Get("organisation/{id}")
 * @Security("is_granted('OrgAdmin', id)")
 * @param int     $id
 * @param Request $request
 *
 * @return View
 */
public function getOrganisationAction($id, Request $request)
{
Run Code Online (Sandbox Code Playgroud)

但是我不喜欢在应用程序中使用魔术字符串的想法,我宁愿使用类常量来进行检查.

像这样的东西:

/**
 * @Rest\Get("organisation/{id}")
 * @Security("is_granted(AppBundle\OrgRoles::ROLE_ADMIN, id)")
 * @param int     $id
 * @param Request $request
 *
 * @return View
 */
public function getOrganisationAction($id, Request $request)
{
Run Code Online (Sandbox Code Playgroud)

但是当我尝试时,我收到以下错误消息:

Unexpected character \"\\\" around position 20 for expression `is_granted(AppBundle\\OrgRoles::ROLE_ADMIN, id)`.
Run Code Online (Sandbox Code Playgroud)

未转义时,如下:

Unexpected character "\" around position 20 for expression …
Run Code Online (Sandbox Code Playgroud)

php expression namespaces symfony

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

在 Laravel 9 上找不到“Symfony\Component\Mailer\Bridge\Mailgun\Transport\MailgunTransportFactory”类

我只是想使用 Mailgun 从我的 Laravel 项目发送电子邮件,并按照官方文档中的步骤进行操作:https ://laravel.com/docs/9.x/mail#mailgun-driver

composer require symfony/mailgun-mailer symfony/http-client

当我尝试发送密码重置电子邮件来测试它时,它会抛出异常:

Class "Symfony\Component\Mailer\Bridge\Mailgun\Transport\MailgunTransportFactory" not found

这是完整的堆栈跟踪:https ://flareapp.io/share/oPRKqyZ7#share

我不知道,但也许是因为这个项目最初是 Laravel 8 项目,一周前我将其更新到 Laravel 9。它是否试图在应用程序目录中找到 Laravel 9 附带的东西或其他东西,但我的项目没有?我不明白。

顺便说一句,如果有帮助的话;该项目使用 Jetstream 以及 Inertia.js 和 Vue.js。所以composer.json现在看起来像这样:

{
    "name": "laravel/laravel",
    "type": "project",
    "description": "The Laravel Framework.",
    "keywords": ["framework", "laravel"],
    "license": "MIT",
    "require": {
        "php": "^8.0.2",
        "fruitcake/laravel-cors": "^2.0",
        "guzzlehttp/guzzle": "^7.2",
        "inertiajs/inertia-laravel": "^0.5.4",
        "laravel/framework": "^9.2",
        "laravel/jetstream": "^2.4",
        "laravel/octane": "^1.0",
        "laravel/sanctum": "^2.14.1",
        "laravel/tinker": "^2.7",
        "sentry/sentry-laravel": "^2.11",
        "symfony/http-client": "^6.0",
        "symfony/mailgun-mailer": "^6.0",
        "tightenco/ziggy": "^1.0"
    },
    "require-dev": …
Run Code Online (Sandbox Code Playgroud)

laravel mailgun symfony-mailer

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

symfony:如何为不同的环境设置配置参数文件?

如何为每个环境设置不同的配置参数文件?

目前,参数parameters.yml都用于环境devprod环境,但我需要不同的参数才能在prod中部署我的应用程序.

symfony symfony-2.8 symfony-3.4 symfony4

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

Symfony:在Doctrine实体方法中使用返回类型提示的表单问题

今天我非常勤奋,并决定返回类型提示我所有的symfony实体方法.所以:

<?php

Class User {
    private string $username;
    public method getUsername(): string {}
}
Run Code Online (Sandbox Code Playgroud)

一切都很好,直到我创建一个表单来创建一个新用户:

$user = new User();
$this->createForm(SignupType::class, $user);
Run Code Online (Sandbox Code Playgroud)

显示表单时,Symfony会自动获取此新实例的属性User $user.但由于它是一个新的实例化,它的username属性当然仍然是null,这是一个不正确的返回类型,因为它需要string.

我应该:

  1. 在Symfony实体中没有返回类型的暗示(meh);
  2. 设置$username = ''(但是帽子有点违背了不允许空白的目的,我可以看到各种各样的错误演变); 要么
  3. 取消映射symfony表单上的字段
  4. 其他可能的方案...

php return-type symfony doctrine-orm php-7

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

如何配置Doctrine以在Symfony 4上使用yaml映射

我是Symfony 4的新手

我使用Doctrine,我想使用yaml实体映射.所以我配置了文件doctrine.yaml并更改type:annotationtype:yml.

当我尝试时php bin/console make:entity,没有生成链接到该实体的yaml映射文件

这是我的doctrine.yaml档案:

parameters:
    # Adds a fallback DATABASE_URL if the env var is not set.
    # This allows you to run cache:warmup even if your
    # environment variables are not available yet.
    # You should not need to change this value.
    env(DATABASE_URL): ''

doctrine:
    dbal:
        # configure these for your database server
        driver: 'pdo_mysql'
        server_version: '5.7'
        charset: utf8mb4

        # With Symfony 3.3, …

mapping yaml symfony doctrine-orm symfony4

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

Symfony 4在DI Extension类中加载和处理自定义Yaml配置文件

我正在尝试按照此处提供的文档在我的应用程序中导入yaml配置文件:http://symfony.com/doc/current/bundles/extension.html但我总是有错误消息:没有扩展能够加载"app"的配置

我的文件位于:config/packages/app.yaml,具有以下结构:

app:  
    list:  
        model1:  
            prop1: value1
            prop2: value2  
        model2:
            ...
Run Code Online (Sandbox Code Playgroud)

由于这是一个简单的应用程序,所有文件都在"src /"中.所以我有:
src/DependencyInjection/AppExtension.php

<?php

namespace App\DependencyInjection;

use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\Config\FileLocator;
use Symfony\Component\HttpKernel\DependencyInjection\Extension;
use Symfony\Component\DependencyInjection\Loader;

class AppExtension extends Extension
{
    public function load(array $configs, ContainerBuilder $container)
    {
        $configuration = new Configuration();
        $config = $this->processConfiguration($configuration, $configs);
    }
}
Run Code Online (Sandbox Code Playgroud)

SRC/DependencyInjection /的configuration.php

<?php

namespace App\DependencyInjection;

use Symfony\Component\Config\Definition\Builder\TreeBuilder;
use Symfony\Component\Config\Definition\ConfigurationInterface;

class Configuration implements ConfigurationInterface
{
    public function getConfigTreeBuilder()
    {
        $treeBuilder = new TreeBuilder();
        $rootNode = $treeBuilder->root('app');

        // …
Run Code Online (Sandbox Code Playgroud)

yaml symfony symfony4

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