天道酬勤,学无止境

MARKER constant override Symfony2 error

So, I have a categories entity set up with a parent_id being self-references. But for some reason when I save the entry in the form I get this error.

Fatal error: Cannot inherit previously-inherited or override constant MARKER from interface Doctrine\Common\Persistence\Proxy in /var/www/html/project/vendor/doctrine/orm/lib/Doctrine/ORM/Proxy/Proxy.php on line 30

Can't figure out what it might be. I set the relationship up according to the Doctrine documentation.

/**
 * Set parent
 *
 * @param string $parent
 * @return Category
 */
public function setParent($parent)
{
    $this->parent = $parent;

    return $this;
}

/**
 * Get parent
 *
 * @return string 
 */
public function getParent()
{
    return $this->parent;
}

Any help would be much appreciated.

评论

I encountered the exact same problem today after doing a change that should not affect Doctrine in any way (I altered a Twig template). After some time I realized that since it's a strange compile error on a strange moment, probably restarting php-fpm would do the trick. And it did.

Maybe restarting Apache does the same if you're on mod_php.

Restarting the server solved the problem for me.

(Using PHP 5.4.15, APC 3.1.13, Apache2.4.4, Doctrine2.2)

Apparently it was a bug in Doctrine-bundle. Updating it to version 1.2.* (and subsequently updating dependent packages) fixed the issue.

I have also encountered this problem with php-fpm 5.4.19, nginx 1.4 and APC 3.1.15 (?) on Centos6-64. As Mark was also mentioning, the use of the Remi repository which I used as well. It seems like the 3.1.15 isn't officially released yet. There isn't even a tag for it on the pecl page! It looks like Remi was trying to fix something to get it work and named it 3.1.15, but can't figure out exactly what it was that he was trying to fix.

Anyway I yum removed the package and installed the current release with the pecl command (now @ 3.1.13), which resolved my problem.

Please understand that APC is dead, unmaintained, no stable version exists for PHP 5.4 (or greater).

I recommend you to switch to:

  • opcache (php-pecl-zendopcache) for opcode cache
  • APCu (php-pecl-apcu) for user data cache (which provides the same API than the old APC, without opcode cache)

受限制的 HTML

  • 允许的HTML标签:<a href hreflang> <em> <strong> <cite> <blockquote cite> <code> <ul type> <ol start type> <li> <dl> <dt> <dd> <h2 id> <h3 id> <h4 id> <h5 id> <h6 id>
  • 自动断行和分段。
  • 网页和电子邮件地址自动转换为链接。

相关推荐
  • Override an image from a bundle
    I have this: ShopBundle Controller Resources public images marker.png views Default index.html.twig In my index.html.twig, I'd like to have this <img src="{{ asset("images/marker.png") }}"/> And I'd love people using my bundle who just want to use their own marker.png to just have to build a bundle inheriting mine and place their image just by following files structure: MyShopBundle Resources public images marker.png Is there any simple way to do this in Symfony2 ? The need seems so simple that I can't believe I didn't find answers already. So, How do you include an image asset in your bundle
  • 覆盖捆绑包中的图像(Override an image from a bundle)
    问题 我有这个: ShopBundle Controller Resources public images marker.png views Default index.html.twig 在我的index.html.twig中,我想要这个 <img src="{{ asset("images/marker.png") }}"/> 我很喜欢那些使用我的包的人,他们只想使用自己的marker.png来构建一个继承我的包,并通过以下文件结构放置其图像: MyShopBundle Resources public images marker.png 在Symfony2中,有什么简单的方法可以做到这一点? 需求是如此简单,以至于我不敢相信我还没有找到答案。 所以, 如何从捆绑资源目录中将图像资产包括在捆绑模板中? 我已经做了./apps/hfr/console assets:install web但是我的模板无法显示正确的网址(/images/marker.png而不是/ bundles / ShopBundle / Resources / public / images / png) 是否可以超越我想要的方式,还是我迷路了? 回答1 解决方案: 使用@语法... {% image '@VendorMyShopBundleBundle/Resources/public/images
  • Google地图错误:拖动后标记的位置未更新(Google maps error: Marker's position is not updated after drag)
    问题 我设置了一个标记,并将其可拖动状态设置为true。 但是当我调用marker.getPosition()我总是得到相同的位置,就像在拖动结束后不会更新标记的位置。 mMap = ((MapFragment) getFragmentManager().findFragmentById(R.id.map_place)) .getMap(); LatLng MYLOCATION = new LatLng(Double.valueOf(myLat), Double.valueOf(myLng)); marker = new MarkerOptions() .position(MYLOCATION) .title(getString(R.string.map_title_my_location)).draggable(true); mMap.addMarker(marker).showInfoWindow(); mMap.moveCamera(CameraUpdateFactory.newLatLngZoom(MYLOCATION, 18)); close.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { // TODO Auto-generated method
  • Symfony2在YAML配置中使用PHP类常量?(Symfony2 Use PHP Class Constant in YAML Config?)
    问题 我知道这可能是不可能的,但是有一种干净的方法可以在YAML config / services / etc中使用PHP类常量。 Symfony2的文件? 例如,如果我有这个: namespace My\Bundle\DependencyInjection; class MyClass { const MY_CONST = 'cookies'; } 可能是这样的情况(在.yml文件中): services: my_service: class: Some\Class arguments: - %My\Bundle\DependencyInjection\MyClass::MY_CONST% 这将有助于保持两者之间的一致性。 回答1 在Symfony 3.2之前的版本中,注入PHP常量只能与XML一起使用: <parameter key="my_service.my_const" type="constant">My\Bundle\DependencyInjection\MyClass::MY_CONST</parameter> 如果要保留yml文件,则只需将xml文件导入到services.yml中。 混合配置样式可能有点难看,但是据我所知,这是唯一的方法。 如果这对您不起作用,则适用于我对您的问题的评论。 回答2 对于Symfony> = 2.4,您可以使用表达语言 例子:
  • 自动布局:removeFromSuperview / removeConstraints引发异常并严重崩溃(AutoLayout: removeFromSuperview / removeConstraints throws exception and crashes hard)
    问题 我们选择性地使用自动布局约束,主要是相对于可编辑字段元素(通常是UITextView,UITextField)来定位标签。 但是,由于为这些字段实现了自动布局,因此在卸载视图,取消分配等操作时,我们会看到一个令人讨厌的异常并崩溃。在尝试在卸载视图之前从视图中删除约束时,会发生异常。 我们的视图/控制器层次结构是这样的: UITableViewController (plain style, but with cell appearance to mimic grouped style) --> UITableViewCell ----> UIViewController (container for editable form) ------> UICollectionViewController (editable form) --------> UICollectionViewCell -----------> UIViewController (editable field) --------------> UILabel (field label) **HAS CONSTRAINTS** --------------> UITextView / UITextField (field value) **HAS CONSTRAINTS** 很多时候,当上级表单元被释放
  • Deploying a Symfony2 project
    We were working on a Symfony2 project. Now, it's done and ready to be deployed. We uploaded the whole project files to the server (via ftp of course) and the database as well. Now when we open any page of it we got just a blank page (empty source code). Cache is clean, logs do not show anything new. We googled the steps of deploying a Symfony2 project to a hosting but we did not find a good explanation (even these ones were about Symfony not-version-2). We believe it maybe a configuration issue, but no idea so far. Any help will be greatly appreciated. Thanks in advance. Edit: the blank page
  • Symfony2 Use PHP Class Constant in YAML Config?
    I know this is probably not possible, but is there a clean way to use a PHP class constant within a YAML config/services/etc. file for Symfony2? For example, if I have this: namespace My\Bundle\DependencyInjection; class MyClass { const MY_CONST = 'cookies'; } Is something like this possible (in a .yml file): services: my_service: class: Some\Class arguments: - %My\Bundle\DependencyInjection\MyClass::MY_CONST% That'd go a long way in helping maintain consistency between the two.
  • GMSPlace returns invalid coordinate (-180, -180), but name and place ID are correct
    I'm trying to implement an autocomplete search on Google Maps that will show the location that the user selects on the map with a marker. Search works fine. The problem is as follows. When I select a location from the search results, I get a GMSPlace object that has the correct name as the selected value, correct place ID (confirmed using this link), but incorrect coordinates (-180.0,-180.0, or the kCLLocationCoordinate2DInvalid constant). I tested this on multiple locations. Most of this code was borrowed from documentation for the Places API. import UIKit import GoogleMaps import
  • Google direction route from current location to known location
    I use the MapsActivity class in this project. On my map you can see many markers. I have many known locations, but in my code I just display two locations for example. I don't understand how to use the direction API and JSON. How can I display the route, distance, and travelling time from my current location (changing) to a known location (constant)? public class MapsActivity extends FragmentActivity { private GoogleMap mMap; // Might be null if Google Play services APK is not available. private Map<Marker, Class<?>> allMarkersMap = new HashMap<Marker, Class<?>>(); @Override protected void
  • 显示特定的路由而不是错误页面(404)-Symfony2(Show a specific route instead of error page (404) - Symfony2)
    问题 我只想显示/ sitemap页面,而不是错误页面/ 404。 当然,我不需要重定向,但我仍然希望设置404 HTTP响应标头。 这可能吗? 我所能看到的就是如何在Twig中设置模板。 我绝对不希望重定向。 回答1 如Symfony Cookbook所示,您可以通过两种方式覆盖错误页面: 覆盖模板使用自定义异常控制器 如果只想显示404( HttpNotFoundException )异常上的/sitemap路由,则可以通过在app/Resources/TwigBundle/views/Exception/error404.html.twig创建一个新模板来覆盖Twig异常模板。 食谱中未显示的另一种方法是使用事件侦听器。 当内核遇到异常时,将调度kernel.exception事件。 默认情况下,该异常被Twig提供的异常侦听捕获。 您可以创建自己的事件侦听器,以侦听kernel.exception事件并呈现页面: <?php use Symfony\Component\HttpKernel\Exception\NotFoundHttpException; use Symfony\Component\HttpKernel\Event\GetResponseForExceptionEvent; use Symfony\Component\HttpFoundation
  • overriding registration FOSUserBundle Symfony2
    I am trying to override Registration Form in FOSUserBundle but i get this error: i have followed this tutorial in the official documentation: Link Could not load type "uae_user_registration" My files are: services.yml # src/Uae/UserBundle/Resources/config/services.yml services: uae_user.registration.form.type: class: Uae\UserBundle\Form\Type\RegistrationFormType arguments: [%fos_user.model.user.class%] tags: - { name: form.type, alias: uae_user_registration } config.yml: app/config/config.yml fos_user: db_driver: orm firewall_name: main user_class: Uae\UserBundle\Entity\User registration: form
  • how to disable security.info and security.debug in monolog symfony2 logging
    I constantly am seeing a bunch of the following log: [2015-02-15 09:08:16] request.INFO: Matched route "AppMainBundle_daftar_toko_province" (parameters: "_controller": "App\MainBundle\Controller\ZHomepageController::daftarTokoAction", "provinceName": "DKI JAKARTA", "_route": "AppMainBundle_daftar_toko_province") [] [] [2015-02-15 09:08:16] security.INFO: Populated SecurityContext with an anonymous Token [] [] [2015-02-15 09:08:16] security.DEBUG: Write SecurityContext in the session [] [] in my prod.log, how can I disable this and I just want to see the errors. Here is my monolog settings
  • 片段中的Android Google Maps(Android Google Maps in Fragment)
    问题 我正在开发一个应用程序,该应用程序的顶部带有一个菜单,该菜单中包含一些按钮。 我正在尝试将google maps添加到按钮之一,但是我不是很成功。 我正在按照本教程进行操作,但不是将Google Maps直接实现为MainActivity而是将它们添加到一个片段中,该片段在按下按钮时启动。 一切正常。 当我按下按钮时,地图就会加载,并且它们会按预期工作。 当我按下主屏幕按钮返回MainActivity它可以正常工作,但是当我想再次加载地图时,它给了我debugging error: Class File Editor: Source not found 这是GoogleMaps片段的代码: public class GoogleMaps extends Fragment{ private GoogleMap googleMap; double latitude = 46.514249; double longitude = 15.080183; public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { final View myFragmentView = inflater.inflate(R.layout.maps_layout
  • 《Effective Java Third》第六章总结:枚举和注解
    第六章 枚举和注解 34.用枚举类型代替 int 常量 在枚举类型被添加到 JAVA 之前,表示枚举类型的一种常见模式是声明一组 int 的常量,使用public static final修饰 缺点: 没有提供任何类型安全性,也没有提供多少表达能力; 没有一种简单的方法可以将 int 枚举常量转换为可打印的字符串; 如果与 int 枚举关联的值发生了更改,则必须重新编译客户端。如果不重新编译,客户端仍然可以运行,但是他们的行为将是错误的; 使用 String 常量代替 int 常量更不可取。 虽然它确实为常量提供了可打印的字符串,但是它可能会导致不知情的用户将字符串常量硬编码到客户端代码中,而不是使用字段名。 如果这样一个硬编码的 String 常量包含一个排版错误,它将在编译时躲过检测,并在运行时导致错误。 此外,它可能会导致性能问题,因为它依赖于字符串比较。 所以最好是使用枚举来代替,因为枚举是一个类,类中再组合了此类类型的常量,能保证安全;也能通过重写toString来打印 实践1: 如下代码这个代码可以工作,但不是很漂亮。 没有 throw 语句就不能编译,因为在技术上可以访问方法的末尾,即使它永远不可能到达; 更糟糕的是,代码是脆弱的。 如果您添加了一个新的枚举常量,但是忘记为开关添加一个相应的大小写,枚举仍然会编译,但是在运行时尝试应用新操作时会失败。 public
  • AutoLayout: removeFromSuperview / removeConstraints throws exception and crashes hard
    We use auto layout constraints selectively, primarily to position labels in relation to editable field elements (UITextView, UITextField, typically). However, since implementing auto layout for these fields, we're seeing a nasty exception and crash whenever we're unloading views, deallocating, etc. The exceptions are happening as it's attempting to remove the constraints from a view before unloading it. Our view/controller hierarchy is as such: UITableViewController (plain style, but with cell appearance to mimic grouped style) --> UITableViewCell ----> UIViewController (container for editable
  • 获取用户的当前位置/坐标(Get User's Current Location / Coordinates)
    问题 如何存储用户的当前位置并在地图上显示该位置? 我能够在地图上显示预定义的坐标,只是我不知道如何从设备接收信息。 我也知道我必须将一些项目添加到Plist中。 我怎样才能做到这一点? 回答1 要获取用户的当前位置,您需要声明: let locationManager = CLLocationManager() 在viewDidLoad()您必须实例化CLLocationManager类,如下所示: // Ask for Authorisation from the User. self.locationManager.requestAlwaysAuthorization() // For use in foreground self.locationManager.requestWhenInUseAuthorization() if CLLocationManager.locationServicesEnabled() { locationManager.delegate = self locationManager.desiredAccuracy = kCLLocationAccuracyNearestTenMeters locationManager.startUpdatingLocation() } 然后在CLLocationManagerDelegate方法中
  • 对SLF4J日志消息进行单元测试的最佳方法是什么?(What is the best way to unit-test SLF4J log messages?)
    问题 我正在使用slf4j,我想对代码进行单元测试,以确保在某些情况下会生成警告/错误日志消息。 我宁愿这些都是严格的单元测试,所以我不希望不必从文件中提取日志记录配置来测试是否生成了日志消息。 我正在使用的模拟框架是Mockito。 回答1 我认为您可以使用自定义附加程序解决您的问题。 创建一个实现org.apache.log4j.Appender的测试附加程序,并在log4j.properties设置您的附加程序,并在执行测试用例时加载它。 如果您从该appender调用测试工具,则可以检查记录的消息 回答2 要在不依赖特定实现(例如log4j)的情况下测试slf4j,可以按照本SLF4J FAQ中的说明提供自己的slf4j日志记录实现。 您的实现可以记录已记录的消息,然后由单元测试对其进行询问以进行验证。 slf4j-test软件包正是这样做的。 这是一个内存中的slf4j日志记录实现,它提供了检索日志消息的方法。 回答3 在并发测试执行的环境中,SLF4J的更好的测试实现真的很好用,是https://github.com/portingle/slf4jtesting 我参与了有关slf4j日志测试和并发测试执行时现有测试方法的局限性的一些讨论。 我决定把我的话写成代码,结果就是git repo。 回答4 创建一个测试规则: import ch.qos.logback
  • Symfony2 FOSUserBundle – Validate against “user active” flag on login
    I have a flag on my users for 'active' and if set to zero or null, I will not allow login. I have tried a couple of approaches and come up short. If I do the logout route the flash message is not preserved, so the user sees nothing. I looked into adding a validation on the login form so that it would throw a normal form error if the flag was not set to true, but in that folder (vendor/Bundles/FOS/UserBundle/Form/Type) I find nothing for login form, only registration and such, so I wouldn't know where to put it or where to inherit from in order to override. I also tried as suggested here to
  • 如何使用毕加索在Google Maps的infoWindow中获取图像-Android(How to get image in infoWindow on Google Maps with picasso - Android)
    问题 我创建了一个实现MapsView的应用程序。 当我单击标记时,它将向我显示信息窗口,其中使用毕加索从数据库中检索数据。 它工作正常,但问题是信息窗口中的图像未显示我所需的图像,但仍显示了占位符图像。 但是,当我单击地图并再次单击标记时,它将显示我所需的图像。 但是,如果我没有在地图上单击(仍在单击标记),它仍然始终向我显示占位符标记。 如何显示我需要的图像(占位符图像将替换为我需要的图像)? 这是我的代码 public void plotMarkers(ArrayList<MyMarker> markers) { if(markers.size() > 0) { for (MyMarker myMarker : markers) { dest = new LatLng(myMarker.getmLatitude(), myMarker.getmLongitude()); markerOption = new MarkerOptions().position(dest); location_marker = mMap.addMarker(markerOption); Target target = new PicassoMarker(location_marker); targets.add(target); ImageView image = new ImageView
  • Symfony2 - FormBuilder - 向字段和输入添加一个类(Symfony2 - FormBuilder - add a class to the field and input)
    问题 我想向 Symfony 应用程序中的某些输入或标签元素添加一个类。 我可以在 Twig 级别上以一种形式做这样的事情: <div class="row"> {{ form_label(form.subject) }} {{ form_widget(form.subject, { 'attr': {'class': 'c4'} }) }} </div> 这工作正常。 但是我必须手动设置和写出每个表单的整个模板。 我实际上想使用: {{ form_widget(form) }} 所以,我在想,如何在FormType某处为标签或输入添加 CSS 类: class SystemNotificationType extends AbstractType { public function buildForm(FormBuilder $builder, array $options) { $builder->add('subject', 'text', array( 'label' => 'Subject' )); 我认为这可能更有用,因为您可以在一个地方配置整个表单。 如何才能做到这一点? 也许我想错了。 回答1 字段的类是应用程序表示层的一部分,因此最好为表单创建一个树枝主题: 在你的 Bundle 的Resources/views/Form中创建一个文件fields.html