我正在尝试创建一个博客,但我不断收到此错误。
BadMethodCallException 方法更新不存在。
我正在尝试编辑帖子并更新数据库。
public function update(Request $request, Post $post)
{
$posts = Post::Find($post);
$posts->update($request->all());
}
Run Code Online (Sandbox Code Playgroud) 如何使用PHP DI加载数据库容器?这是我迄今为止尝试过的变体之一。
设置.php
<?php
use MyApp\Core\Database;
use MyApp\Models\SystemUser;
return [
'Database' => new Database(),
'SystemUser' => new SystemUser()
];
Run Code Online (Sandbox Code Playgroud)
初始化文件
$containerBuilder = new \DI\ContainerBuilder();
$containerBuilder->addDefinitions('Settings.php');
$container = $containerBuilder->build();
Run Code Online (Sandbox Code Playgroud)
系统用户详细信息.php
<?php
namespace MyApp\Models\SystemUser;
use MyApp\Core\Database;
use MyApp\Core\Config;
use MyApp\Helpers\Session;
/**
*
* System User Details Class
*
*/
class SystemUserDetails
{
/*=================================
= Variables =
=================================*/
private $db;
/*===============================
= Methods =
================================*/
/**
*
* Construct
*
*/
public function __construct(Database $db)
{
# Get database instance
// …Run Code Online (Sandbox Code Playgroud) 我执行了make:crud为实体用户生成一些文件的命令。
一切都像一种魅力,但我在编辑用户时遇到了一个问题。当我编辑用户时,我可以:
或者
从生成的用户“编辑”控制器:
/**
* @Route("/{id}/edit", name="user_edit", methods={"GET","POST"})
*/
public function edit(Request $request, User $user): Response
{
$form = $this->createForm(UserType::class, $user);
$form->handleRequest($request);
if ($form->isSubmitted() && $form->isValid()) {
// HERE : How can I check if the password was changed ?
$this->getDoctrine()->getManager()->flush();
return $this->redirectToRoute('user_index', [
'id' => $user->getId(),
]);
}
return $this->render('user/edit.html.twig', [
'user' => $user,
'form' => $form->createView(),
'title' => 'edit userr'
]);
}
Run Code Online (Sandbox Code Playgroud)
如何检查密码是否已更改?用户变量包含新密码值...
如果密码是新的,我必须使用编码器服务。如果没有,我只需要用新数据更新用户
我安装了 Codeigniter 4.0.2 并做了以下更改:
1-CI_ENVIRONMENT = development在 .env 文件中
2-SetEnv CI_ENVIRONMENT development在公用文件夹中的 .htaccess
3-$useKint = true;在公共文件夹中的主 index.php 文件中添加
当我在本地主机上打开时,会呈现欢迎页面,但不会呈现任何调试工具栏。我错过了什么吗?
我有一个 Symfony 项目,我试图在我的控制器中获取可用命令的列表,所以我尝试执行list-command(连同--format=xml)来实现这一点。
我使用此处列出的代码从控制器运行命令,但最终出现错误“不推荐使用连接提供程序作为第一个构造函数参数已弃用”。
这是代码:
$application = new Application($kernel);
$application->setAutoExit(false);
$input = new ArrayInput(['command' => 'list', '--format' => 'xml']);
$output = new BufferedOutput();
$application->run($input, $output);
$content = $output->fetch();
Run Code Online (Sandbox Code Playgroud)
提到的错误发生在vendor\doctrine\dbal\lib\Doctrine\DBAL\Tools\Console\Command\RunSqlCommand.php. 这是完整的跟踪:
$application = new Application($kernel);
$application->setAutoExit(false);
$input = new ArrayInput(['command' => 'list', '--format' => 'xml']);
$output = new BufferedOutput();
$application->run($input, $output);
$content = $output->fetch();
Run Code Online (Sandbox Code Playgroud)
奇怪的是,无论是否将格式设置为 XML,运行“bin/console list”(或只是“bin/console”)都不会显示错误,使用上述代码从我的控制器运行任何其他命令也可以正常工作。
我正在使用 Symfony 5.1.7 和 Doctrine-bundle 2.1,我已经尝试将学说/持久性降级到 1.x,因为 2.x 显示某些库存在一些问题,但都无济于事。
如何在 Symfony 5.2 中完全禁用缓存?
我使用 PHP 配置文件 (services.php) 而不是yaml 文件。在文档中,我找不到任何匹配的内容。
我创建了一个带有选项卡的页面(使用引导程序),并且所有选项卡都有自己的表单。而且它们都工作得很好。我的问题是当我收到表单错误时,我想打开错误所在的选项卡。
我当前的控制器代码:
public function add(Request $request, EntityManagerInterface $em): Response {
$this->denyAccessUnlessGranted('ROLE_USER');
$entityAdd = new \App\Entity\add();
$form = $this->createForm(\App\Form\Add::class, $entityAdd);
$form->handleRequest($request);
if ($form->isSubmitted() && $form->isValid()) {
Run Code Online (Sandbox Code Playgroud)
AddFormType.php 中的函数
public function buildForm(FormBuilderInterface $builder, array $options) {
$builder
->add(...)
->add(...)
->add(...)
->getForm()
;
}
Run Code Online (Sandbox Code Playgroud)
我不是自己创建表单,我使用的是 symfony 表单组件,但我不确定如何修改表单方法以将表单哈希(例如 /add#list-tab1)添加到表单方法中。
{{ form_start(AddForm) }}
{{ form_row(AddForm.name1) }}
{{ form_row(AddForm.name2) }}
{{ form_row(AddForm.save) }}
{{ form_end(AddForm) }}
Run Code Online (Sandbox Code Playgroud) 我对discord.js 斜杠命令有疑问。
正如您在我的代码中看到的,我将名称设置为“Name”和“Age”,所以我不明白问题是什么。
这是我的错误:
error: (node:16004) UnhandledPromiseRejectionWarning: DiscordAPIError: Invalid Form Body
options[0].name: Command name is invalid
Run Code Online (Sandbox Code Playgroud)
这是我的代码:
const Discord = require('discord.js');
require("dotenv").config();
const client = new Discord.Client();
client.on('ready', async () => {
console.log(`Logged in as ${client.user.tag}!`);
const getApp = (guildid) => {
const app = client.api.applications(client.user.id);
if(guildid){
app.guilds(guildid);
}
return app;
}
await getApp("842486032842358784").commands.post({
data: {
name: 'embed',
description: 'Displays embed',
options: [
{
name: 'Name',
description: 'Your Name',
required: true,
type: 3
},
{
name: 'Age',
description: 'Your Age', …Run Code Online (Sandbox Code Playgroud) Symfony 2 遇到一些问题。
尝试使用我的实体从表中获取一些行。
这是实体
namespace AppBundle\Entity;
use Doctrine\ORM\Mapping as ORM;
/**
* @ORM\Entity
* @ORM\Table(name="articles")
*/
class Article
{
/**
* @var integer $id
*
* @ORM\Id
* @ORM\Column(name="id", type="integer")
* @ORM\GeneratedValue(strategy="AUTO")
*/
protected $id;
/**
* @ORM\Column(type="string" name="title")
*/
protected $title;
/**
* @ORM\Column(type="int" name="author_id")
*/
protected $authorId;
/**
* @ORM\Column(type="datetime" name="creation_date")
*/
protected $creationDate;
/**
* @ORM\Column(name="string")
*/
protected $content;
public function getId()
{
return $this->id;
}
public function getTitle()
{
return $this->title;
}
public function getAuthorId() …Run Code Online (Sandbox Code Playgroud) 我有一个字符串,其中有带双引号的部分。我试图用单引号替换所有双引号,除了那些有转义的双引号 ie: \"。
我正在尝试构建一个与所有匹配的正则表达式,"除了像\"
所以当我使用时,preg_replace我会得到如下。
"love" -> 'love'
"John said \"HI\"" - > 'John said \"HI\"'
Run Code Online (Sandbox Code Playgroud)
我尝试了以下完全相反的方法。
[<^\\]"
Run Code Online (Sandbox Code Playgroud) php ×5
symfony ×4
bootstrap-4 ×1
containers ×1
debugging ×1
discord ×1
discord.js ×1
doctrine ×1
doctrine-orm ×1
javascript ×1
kint ×1
laravel ×1
laravel-5.5 ×1
node.js ×1
oop ×1
php-di ×1
regex ×1
symfony4 ×1