我正在使用Twig Date扩展来获得工作时间_diff.
{{ photo.getCreationDate|time_diff }}
Run Code Online (Sandbox Code Playgroud)
我想让它成为多语言.它说,我已经阅读了文档
要获得可翻译的输出,请将Symfony\Component\Translation\TranslatorInterface作为构造函数参数.返回的字符串格式为diff.ago.XXX或diff.in.XXX,其中XXX可以是任何有效单位:秒,分钟,小时,日,月,年.
我不知道怎么做,但似乎它对我不起作用.
这就是我在控制器中尝试的方式.
$ twig = new Twig_Environment(new TranslatorInterface()); $ twig-> addExtension(new Twig_Extensions_Extension_Date());
我有下一个错误
错误:无法实例化Symfony\Component\Translation\TranslatorInterface接口
Twig_Environment构造函数正在等待Twig_LoaderInterface对象,而不是TranslatorInterface.
如何让我翻译time_diff输出?
谢谢
我刚刚将symfony从2.7更新到3.0并且遇到了一些问题..
它无法加载我的表单类型.这是一个例子.
的services.xml
app.search:
class: AppBundle\Form\Type\SearchFormType
tags:
- { name: form.type, alias: app_search }
Run Code Online (Sandbox Code Playgroud)
多数民众赞成我试图创造形式.
$form = $this->createForm('app_search', new Search());
Run Code Online (Sandbox Code Playgroud)
SearchFormType
namespace AppBundle\Form\Type;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\FormBuilderInterface;
class SearchFormType extends AbstractType
{
public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder->add('phrase', 'text');
}
public function getBlockPrefix()
{
return 'app_search';
}
}
Run Code Online (Sandbox Code Playgroud)
得到下一个错误:
在...中呈现模板("无法加载类型"app_search"")期间抛出异常
在symfony 3.0中应该如何?
谢谢 !
我有2个实体,用户和追随者.
/**
* @ORM\Entity
* @ORM\Table(name="users")
*/
class User extends BaseUser
{
/**
* @ORM\OneToMany(targetEntity="Follower", mappedBy="user")
*/
protected $followers;
/**
* @ORM\OneToMany(targetEntity="Follower", mappedBy="follower")
*/
protected $followings;
}
/**
* @ORM\Entity
* @ORM\Table(name="follows")
*/
class Follower
{
/**
* @ORM\ManyToOne(targetEntity="User", inversedBy="followers")
*/
protected $user;
/**
* @ORM\ManyToOne(targetEntity="User", inversedBy="followers")
*/
protected $follower;
}
Run Code Online (Sandbox Code Playgroud)
用户有关注者($粉丝)和关注者($ followers).
我不知道为什么,但我的开发者说:
映射AppBundle\Entity\User#followings和AppBundle\Entity\Follower#follower彼此不一致.
映射AppBundle\Entity\Follower#follower和AppBundle\Entity\User#followers彼此不一致.
为什么他们不存在而应该这样做?
我在使用 symfony 控制器时遇到一些问题,为什么要发送 ajax 请求。
这是我的控制器
namespace AppBundle\Controller;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Symfony\Component\HttpFoundation\Request;
use AppBundle\Entity\Follow;
use AppBundle\Exception\FollowException;
class FollowController extends Controller
{
public function ajaxAction(Request $request)
{
$authChecker = $this->get('security.authorization_checker');
if(!$authChecker->isGranted('ROLE_USER')) {
echo 'Access Denied';
}
$userId = $request->request->get('id');;
$em = $this->getDoctrine()->getManager();
$user = $this->getUser();
$followedUser = $em->getRepository('AppBundle:User')->find($userId);
if(!$followedUser) {
echo 'User not exist';
}
$follow = new Follow();
$follow->setUserId($followedUser->getId());
$follow->setFollowerId($user->getId());
$em->persist($follow);
$em->flush();
echo 'Success';
return true;
}
}
Run Code Online (Sandbox Code Playgroud)
这是我的简单ajax请求
$('#subscribe-button').click(function() {
$.ajax({
type: 'POST',
url: '/web/app_dev.php/follow',
data: 'id={{ …Run Code Online (Sandbox Code Playgroud) 我遇到了Docker的麻烦.
这是我的DockerFile
FROM alpine:3.3
WORKDIR /
COPY myinit.sh /myinit.sh
ENTRYPOINT ["/myinit.sh"]
Run Code Online (Sandbox Code Playgroud)
myinit.sh
#!/bin/bash
set -e
echo 123
Run Code Online (Sandbox Code Playgroud)
这就是我建立我的形象的方式
docker build -t test --no-cache
Run Code Online (Sandbox Code Playgroud)
运行日志
Sending build context to Docker daemon 3.072 kB
Step 1 : FROM alpine:3.3
---> d7a513a663c1
Step 2 : WORKDIR /
---> Running in eda8d25fe880
---> 1dcad4f11062
Removing intermediate container eda8d25fe880
Step 3 : COPY myinit.sh /myinit.sh
---> 49234cc3903a
Removing intermediate container ffe6227c921f
Step 4 : ENTRYPOINT /myinit.sh
---> Running in 56d3d748b396
---> 060f6da19513
Removing intermediate container …Run Code Online (Sandbox Code Playgroud) 我在Symfony 2中遇到了一个奇怪的翻译问题.
这是我的config.yml
imports:
- { resource: parameters.yml }
- { resource: security.yml }
- { resource: services.yml }
# Put parameters here that don't need to change on each machine where the app is deployed
# http://symfony.com/doc/current/best_practices/configuration.html#application-related-configuration
framework:
#esi: ~
translator: { fallbacks: ['%locale%'] }
secret: "%secret%"
router:
resource: "%kernel.root_dir%/config/routing.yml"
strict_requirements: ~
form: ~
csrf_protection: ~
validation: { enable_annotations: true }
#serializer: { enable_annotations: true }
templating:
engines: ['twig']
#assets_version: SomeVersionScheme
trusted_hosts: ~
trusted_proxies: ~
session:
# handler_id set …Run Code Online (Sandbox Code Playgroud) 我正在尝试在我的nginx配置文件中设置client_max_body_size.
server {
listen 80;
server_name ****.com;
root ****;
client_max_body_size 32m
location / {
try_files $uri /app.php$is_args$args;
}
location ~ ^/(app_dev|config)\.php(/|$) {
fastcgi_pass 127.0.0.1:9000;
fastcgi_split_path_info ^(.+\.php)(/.*)$;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $realpath_root$fastcgi_script_name;
fastcgi_param DOCUMENT_ROOT $realpath_root;
}
location ~ ^/app\.php(/|$) {
fastcgi_pass 127.0.0.1:9000;
fastcgi_split_path_info ^(.+\.php)(/.*)$;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $realpath_root$fastcgi_script_name;
fastcgi_param DOCUMENT_ROOT $realpath_root;
internal;
}
}
Run Code Online (Sandbox Code Playgroud)
我收到错误:/etc/nginx/sites-enabled/****.com中"client_max_body_size"指令中的参数数量无效
我的conf怎么了?
我在 Windows 上安装了 php 只是为了有机会运行 php 命令。
我需要启用一些扩展(mbstring、openssl)的命令之一。我已经在 php.ini 中启用了它们,但仍然看不到它,因为 php 没有重新加载。我在 Windows 上没有任何网络服务器(没有 IIS、Apache、Nginx)。我怎样才能在没有任何网络服务器的情况下重新加载 php 和 php.ini ?
谢谢!
我在数据库中有很多类别.
这是类别实体
namespace AppBundle\Entity;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\Validator\Constraints as Assert;
/**
* @ORM\Entity
* @ORM\Table(name="categories")
*/
class Category
{
/**
* @ORM\Id
* @ORM\Column(type="integer")
* @ORM\GeneratedValue(strategy="AUTO")
*/
protected $id;
/**
* @ORM\ManyToOne(targetEntity="Category")
*/
protected $rootCategory;
/**
* @ORM\Column(type="text")
*/
protected $name;
/**
* Get id
*
* @return integer
*/
public function getId()
{
return $this->id;
}
/**
* Set name
*
* @param string $name
*
* @return Category
*/
public function setName($name)
{
$this->name = $name; …Run Code Online (Sandbox Code Playgroud) php ×7
symfony ×6
doctrine-orm ×2
ajax ×1
docker ×1
dockerfile ×1
doctrine ×1
nginx ×1
translation ×1
twig ×1