我想在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)
有什么想法吗?我没有更改任何东西,我只运行这些命令.
我有一个ManyToMany我闯入OneToMany和ManyToOne关系.我想构建一个具有复选框而不是集合的表单,我正在使用'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) 我有一个多步骤表单供用户在会议中注册,所有步骤都在同一registration.blade.php页面,在步骤1和步骤2完成ajax请求以验证表单字段.
步骤是:
我怀疑是在第2步和第3步之间.
如果执行下面的代码需要所选的付款方式参考,那么会生成一些付款参考,然后在步骤3中向用户提供该参考.当用户付款时,系统会收到通知并应插入付款表中price,payment_method_id,registration_id和status(付费).
使用参考资料处理付款的代码:
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) 我有一个控制器,其中包含三个功能(注册、登录、忘记密码)。对于登录和注册,它工作正常,但是当我尝试在邮递员中使用 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) 我正在使用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) 我只是想使用 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) 如何为每个环境设置不同的配置参数文件?
目前,参数parameters.yml都用于环境dev和prod环境,但我需要不同的参数才能在prod中部署我的应用程序.
今天我非常勤奋,并决定返回类型提示我所有的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.
我应该:
$username = ''(但是帽子有点违背了不允许空白的目的,我可以看到各种各样的错误演变); 要么我是Symfony 4的新手
我使用Doctrine,我想使用yaml实体映射.所以我配置了文件doctrine.yaml并更改type:annotation为type: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, … 我正在尝试按照此处提供的文档在我的应用程序中导入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) symfony ×6
php ×5
doctrine-orm ×3
laravel ×3
symfony4 ×3
yaml ×2
exception ×1
expression ×1
jquery ×1
laravel-8 ×1
mailgun ×1
mapping ×1
namespaces ×1
php-7 ×1
return-type ×1
symfony-2.8 ×1
symfony-3.4 ×1
zend-form2 ×1