标签: symfony

Doctrine/symfony2类的对象无法转换为字符串

我在Symfony 2中的项目有问题我得到了这个错误

Catchable Fatal Error: Object of class Nicearma\MemesBundle\Entity\Usuario could not be converted to string in C:\wamp\www\24memes\vendor\doctrine-dbal\lib\Doctrine\DBAL\Statement.php line 131
Run Code Online (Sandbox Code Playgroud)

问题是,我试图做一个表格,从UsuarioInfo类,这个类有一个对象Usuario,表单工作正常,但去发送信息我得到消息而我没有找到解决方案,任何人都知道如何解决这个?我有这个文件

registro.html.twig

<div class="usuario">
{{ form_row(form.usuario) }}
</div>
{{ form_rest(form) }}
Run Code Online (Sandbox Code Playgroud)

Usuario.php

namespace Nicearma\MemesBundle\Entity;

use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\Security\Core\User\UserInterface;
use Symfony\Component\Validator\Constraints as Assert;

/**
 * Nicearma\MemesBundle\Entity\Usuario
 *
 * @ORM\Table(name="usuario")
 * @ORM\Entity(repositoryClass="Nicearma\MemesBundle\Repository\Usuario")
 */
class Usuario implements UserInterface
{
    /**
     * @var integer $id
     * @ORM\Column(name="id", type="integer", nullable=false)
     * @ORM\Id
     * @ORM\GeneratedValue(strategy="IDENTITY")
     */
    private $id;

    /**
     * @var string $nombre
     * @Assert\Type(type="String") …
Run Code Online (Sandbox Code Playgroud)

php doctrine symfony doctrine-orm

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

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

如何自动更新学说实体的属性?

我在我的symfony 2项目中创建了一个doctrine实体类,现在我想在实体管理器保存之前自动设置一个属性.是否有一些钩子要实现或如何解决我的问题?

symfony doctrine-orm

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

如何在没有pha​​r支持的情况下在PHP 5.2.8上安装symfony(Composer依赖)?

我一直试图在我的网站上安装symfony但是我没有取得什么成功,因为它取决于作曲家.

安装:

php -r "eval('?>'.file_get_contents('https://getcomposer.org/installer'));"
Run Code Online (Sandbox Code Playgroud)

当我尝试安装时(所有安装选项似乎都需要phar支持)我得到了这个输出:

-----------------------------------------------------------
Warning: Unexpected character in input:  '\' (ASCII=92) state=1 in Command line code(1) : eval()'d code on line 378
#!/usr/bin/env php
Some settings on your machine make Composer unable to work properly.
Make sure that you fix the issues listed below and run this script again:

The phar extension is missing.
Install it or recompile php without --disable-phar

Your PHP (5.2.8) is too old, you must upgrade to PHP 5.3.2 or higher.
-----------------------------------------------------------

我没有权限安装不同版本的PHP,因为我使用的付费虚拟主机有点限制.我有什么选择?

php install phar symfony

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

如何在同一个Doctrine2对象上正确插入或更新

我有这段代码:

$entity = $em->getRepository('AppBundle:Representative')->find($soqlObj1['records'][0]['Id']);

if ($entity === null) {
    $entity = new Representative();
    $em->persist($entity);
}

// we set the values from veeva
$entity->setVeevaRepId($soqlObj1['records'][0]['Id']);
$entity->setEmail($soqlObj1['records'][0]['Email']);
...

$em->flush();
Run Code Online (Sandbox Code Playgroud)

这是实体的一部分Representative

class Representative
{
    /**
     * @ORM\Id()
     * @ORM\Column(type="string", length=45, nullable=false, unique=true)
     * @ORM\GeneratedValue()
     * @Expose()
     */
    protected $veeva_rep_id;

    /**
     * @var string
     * @ORM\Column(type="string", length=45)
     * @Expose()
     */
    protected $display_name;

    /**
     * @var string
     * @ORM\Column(type="string", length=255)
     * @Expose()
     */
    protected $avatar_url = 'https://pdone.s3.amazonaws.com/avatar/default_avatar.png';

    /**
     * @var string
     * @ORM\Column(type="string", length=45) …
Run Code Online (Sandbox Code Playgroud)

php symfony doctrine-orm symfony-2.6

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

重定向|从旧URL转发到新URL

我有一个路由和方法以这种方式操纵URL:

http://domain.com/combivent?email=WGA1cUtKZi4
Run Code Online (Sandbox Code Playgroud)

现在该URL已更改为此URL:

http://domain.com/?email=WGA1cUtKZi4
Run Code Online (Sandbox Code Playgroud)

但旧的电子邮件仍旧保留旧电子邮件.我需要将每个URL从旧方式重定向到新方式.例如,如果我调用它,http://domain.com/combivent?email=WGA1cUtKZi4那么我应该重定向到http://domain.com/?email=WGA1cUtKZi4如何在Symfony2中实现这一点?我可以在路由中使用任何类型的通配符,还是我需要保留这两种方法并在内部处理它?这可以在.htaccess水平上完成吗?有什么建议?

这是.htaccess看起来像:

<IfModule mod_rewrite.c>
    RewriteEngine On

    RewriteCond %{REQUEST_URI}::$1 ^(/.+)/(.*)::\2$
    RewriteRule ^(.*) - [E=BASE:%1]

    RewriteCond %{HTTP:Authorization} .
    RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]

    RewriteCond %{ENV:REDIRECT_STATUS} ^$
    RewriteRule ^app\.php(/(.*)|$) %{ENV:BASE}/$2 [R=301,L]

    RewriteCond %{REQUEST_FILENAME} -f
    RewriteRule .? - [L]

    # Remove combivent word from the URL when call a brand page
    RewriteRule ^combivent?email=([^/]+)$  /?email=$1 [L,QSA,R=301]

    RewriteRule .? %{ENV:BASE}/app.php [L]    
</IfModule>
Run Code Online (Sandbox Code Playgroud)

此外,这domain.com是共享三个域的VirtualHost的别名.将VH定义视为:

ServerName maindomain.com
ServerAlias domain.com
ServerAlias domain1.com
Run Code Online (Sandbox Code Playgroud)

更新

以下是完整.htaccess定义: …

php .htaccess redirect url-routing symfony

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

使用ajax和Symfony2显示数据

我想通过点击链接显示带有jquery的数据.这是代码,但缺少一些代码jquery来浏览数据和代码twig来显示它们.

这是Twig:

<a href  class="list">List</a>

<div id="travels">

  // display data here

</div>

<script>
    $(document).ready(function () {
        $(".list").click(function () {

            $.ajax({
                type: 'POST',
                dataType: 'json',
                url: Routing.generate('travel_list_ajax'),
                success: function () {
                   // rest of code

                }
            });
            return false;
        });
    });
</script>
Run Code Online (Sandbox Code Playgroud)

行动

public function listAjaxAction(Request $request)
{
    if ($request->isXmlHttpRequest()) {

        $em = $this->getDoctrine()->getManager();

        $travels = $em->getRepository('AppBundle:Travel')->findAll();

        $response = new JsonResponse();

        return $response->setData(array('travels'=>$travels));
    }
    return null;

}
Run Code Online (Sandbox Code Playgroud)

ajax jquery symfony

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

Composer 显示 2 个兼容包之间的冲突(原始)

我在尝试composer install我的依赖项时出错。相同的错误composer update

它说 symfony/web-server-bundle 4.3.3 和 symfony 3.4 之间存在冲突,但这些包应该是兼容的:

这是我的控制台输出:

$ composer install --ignore-platform-reqs
Deprecation warning: Your package name theredled/. is invalid, it should have a vendor name, a forward slash, and a package name. The vendor and package name can be words separated by -, . or _. The complete name should match "[a-z0-9]([_.-]?[a-z0-9]+)*/[a-z0-9]([_.-]?[a-z0-9]+)*". Make sure you fix this as Composer 2.0 will error.
Deprecation warning: require.beberlei/DoctrineExtensions is invalid, it should not …
Run Code Online (Sandbox Code Playgroud)

php symfony composer-php

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

如何从我的 ArrayCollection 获取数据?

我正在尝试通过学说从我的数组集合中加载数据:

 $pages = $this->em->getRepository(Pages::class)->findAll();
Run Code Online (Sandbox Code Playgroud)

结果是:

2 => Pages^ {#1598 ?
-id: 3
-name: "cat"
-membergroup: PersistentCollection^ {#1603 ?
  -snapshot: []
  -owner: Pages^ {#1598}
  -association: array:16 [ …16]
  -em: EntityManager^ {#278 …11}
  -backRefFieldName: "pages"
  -typeClass: ClassMetadata {#693 …}
  -isDirty: false
  #collection: ArrayCollection^ {#1604 ?
    -elements: []
  }
  #initialized: false
}
Run Code Online (Sandbox Code Playgroud)

}

问题是,我希望成员组 ArrayCollection 中有一个元素。但它是空的。

php doctrine arraycollection symfony

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

带有等号的 Twig AND 运算符

在我的 Symofny 项目中,我正在为具有特定状态的实体显示按钮。

如果我只为一种状态定义它可以工作,但是当我尝试使用两种状态时它不会。但它适用于如果我把例如' !='。

{% if (item.status == 'free') and (item.status == 'paid') %}

     <a type="button" href="{{ path('my_path', {'id':item.id}) }}" class="btn btn-primary">Btn</a>

  {% endif %}
Run Code Online (Sandbox Code Playgroud)

same as按照树枝文档中的描述进行了尝试。

php symfony twig

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