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) 我正在尝试建立这样的连接:
{% set img_src='images/ksiazki/'~{{new_book.tytul}}~'.jpg' %}
Run Code Online (Sandbox Code Playgroud)
但我仍然收到此错误:
哈希键必须是带引号的字符串、数字、名称或括在括号中的表达式(值“的意外标记“标点符号”)
怎么了?
在从 PHP 5.5 升级到 PHP 7.0 的过程中,Symfony 项目遇到了问题。
已遵循http://www.doctrine-project.org/2016/06/09/odm-1-1-0-and-1-0-6.html中的步骤,以确保 mongo-ext 符合原则。没有发生兼容性升级。
但出现以下异常:
PHP Fatal error: Cannot use 'String' as class name as it is reserved in
... vendor/doctrine/mongodb-odm/lib/Doctrine/ODM/MongoDB/Mapping/Annotations/String.php on line 26
Run Code Online (Sandbox Code Playgroud)
该问题很可能与composer.json 中的配置问题有关
哪个要求阻止作曲家更新安装正确的原则/mongodb?
PHP 版本 7.0.13-0ubuntu0.16.04.1 (cli) (NTS)
{
"name": "foo/bar",
"license": "proprietary",
"type": "project",
"autoload": {
"psr-4": {
"": "src/"
},
"classmap": [
"app/AppKernel.php",
"app/AppCache.php"
]
},
"autoload-dev": {
"psr-4": {
"Tests\\": "tests/"
}
},
"require": {
"php": "^7.0",
"symfony/symfony": "3.2.*",
"doctrine/orm": "^2.5",
"doctrine/doctrine-bundle": "^1.6",
"doctrine/doctrine-cache-bundle": …Run Code Online (Sandbox Code Playgroud) 我熟悉Symfony Form类API。
我没有得到的一件事是这种方法:
/**
* Returns the extra data.
*
* @return array The submitted data which do not belong to a child
*/
public function getExtraData()
{
return $this->extraData;
}
Run Code Online (Sandbox Code Playgroud)
我无法使用此方法返回任何值。当我尝试发布未映射/无法识别的输入时,它总是返回一个空数组。
请帮助我了解此方法的实际用例。数据何时变为“额外”?
一个代码示例将是理想的。
非常感谢你。
当我尝试访问 symfony 2.8 中的获取结果时,出现此错误。这是我的代码
public function staticAction(Request $request)
{
$jobid = $this->get('session')->get('jobid');
$jobDetails = $this->getVacancyData($jobid);
echo "<pre>";
var_dump($jobDetails);
$description = $jobDetails->jobDescription;
return $this->render('FrontEnd/job.html.twig', array('jobdetails' => $jobDetails ));
}
public function getVacancyData($id){
$vacancy = $this->getDoctrine()
->getRepository(VacancyEntity::class)
->findOneBy(array('id' => $id));
if (!$vacancy) {
throw $this->createNotFoundException();
}else{
return $vacancy;
}
}
Run Code Online (Sandbox Code Playgroud)
以下行发生错误,
$description = $jobDetails->jobDescription;
Run Code Online (Sandbox Code Playgroud)
怎么解决这个问题呢?
我想通过使用Symfony 3.4中的compilerPass来覆盖FosUserbundle的控制器(RegistartionController),所以这是我的代码
=== 注册用户编译器密码 ===
<?php
namespace myBundle;
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
use Symfony\Component\DependencyInjection\ContainerBuilder;
class RegisterUserCompilerPass extends CompilerPassInterface
{
public function process(ContainerBuilder $container)
{
$container
->getDefinition('fos_user.registration.controller')
->setClass(MyBundle\Controller\ReplaceRegistrationController::class) ;
}
}
Run Code Online (Sandbox Code Playgroud)
这是添加时的文件,将其添加到主包类中
<?php
namespace MyBundle;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\HttpKernel\Bundle\Bundle;
use MyBundle\DependencyInjection\Compiler\RegisterUserCompilerPass ;
// use Crypto\UserBundle\Manager\ReplaceRegistration ;
class CryptoUserBundle extends Bundle
{
public function build(ContainerBuilder $container)
{
parent::build($container);
$container->addCompilerPass(new RegisterUserCompilerPass() );
}
}
Run Code Online (Sandbox Code Playgroud)
当访问我的注册路径时我得到
编译错误:类 MyBundle\DependencyInjection\Compiler\RegisterUserCompilerPass 无法从接口 Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface 扩展
我有一个带有授权服务的Symfony 4应用程序,我想处理一些更高级别的逻辑,以确定给定用户是否可以访问给定路由.
我实现了这个 BaseController
namespace App\Controller;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use App\Services\Authorize;
class BaseController extends Controller {
private $auth;
public function __construct(Authorize $auth){
$this->auth = $auth;
}
public function initBaseController() {
$this->auth->do_authorize();
}
}
Run Code Online (Sandbox Code Playgroud)
而Authorize服务是这样的:
namespace App\Services;
use Symfony\Component\HttpFoundation\RedirectResponse;
use App\Services\Session;
class Authorize {
private $session;
public function __construct(Session $session){
$this->session = $session;
}
public function do_authorize(){
if($this->session->validate('fake_token'){
return $this->redirectToRoute('login-portal'); // ** ERROR **
}
}
}
Run Code Online (Sandbox Code Playgroud)
因此,BaseController如果会话不存在或使用Authorize服务无效,则使用和重定向到登录页面全局实现此过程.
但是重定向行会抛出错误,尽管这是关于此主题的symfony文档中的正确实现.
我相信这是因为我试图从服务中重定向,而不是控制器.
如何从服务中重定向?
我想做的事情很简单,但是我找不到解决方案。我已经开始使用与Doctrine捆绑在一起的Symfony4开发我的应用程序。最初,我设计了数据库模型,但是在开发过程中,我意识到原始解决方案对于我想做的事情是错误的方式。现在,我想从实体中删除一个属性。在普通的SQL中,我会ALTER TABLE table DROP COLUMN column然后使用新参数重新创建它。但是,该解决方案在Doctrine中给了我一个错误,因此我也更改了PHP模型。同样,另一个错误。好的,这看起来不像我想要的方式。除了在学说方面深入研究之外,我的问题是否有解决方案?最好的方法就是上面的SQL命令中所述的简单方法?
对于我使用的 symfony 形式和树枝
{{ form_errors(form) }}
Run Code Online (Sandbox Code Playgroud)
使用bootstrap_4_horizontal_layout.html.twig,它工作正常,输出如下:
<span class="alert alert-danger d-block"><span class="d-block">
<span class="form-error-icon badge badge-danger text-uppercase">Error</span> <span class="form-error-message">Error</span>
</span></span>
Run Code Online (Sandbox Code Playgroud)
但我需要对其进行自定义以翻译消息旁边的引导错误标签。我可以在哪里定制它?
我正在尝试使用 Symfony 进程组件执行 ffmpeg 命令,但命令未被处理。我究竟做错了什么?我收到错误
命令“'ffmpeg -i [.........]'失败。退出代码:127(未找到命令)”
<?php
$info = pathinfo($file);
$dir = "{$info['dirname']}/{$info['filename']}";
File::makeDirectory($dir, 0755, true)
$process = new Process(["ffmpeg -i {$info['basename']} -codec copy -map 0 -f segment -segment_list {$dir}/playlist.m3u8 -segment_list_flags +live -segment_time 10 {$dir}/{$info['filename']}_%02d.ts"]);
$process->setWorkingDirectory($info['dirname']);
$process->start();
if (!$process->isSuccessful()) {
throw new ProcessFailedException($process);
}
echo $process->getOutput();
?>
Run Code Online (Sandbox Code Playgroud) symfony ×10
php ×4
doctrine-orm ×2
symfony4 ×2
twig ×2
bootstrap-4 ×1
doctrine ×1
doctrine-odm ×1
mongodb ×1
overriding ×1
php-7 ×1
php-7.1 ×1
service ×1
symfony-2.8 ×1