troubleshooting.rst 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. Troubleshooting
  2. ===============
  3. The toString method
  4. -------------------
  5. Sometimes the bundle needs to display your model objects, in order to do it, objects are converted to string by using the `__toString`_ magic method.
  6. Take care to never return anything else than a string in this method.
  7. For example, if your method looks like that :
  8. .. code-block:: php
  9. public function __toString()
  10. {
  11. return $this->getTitle();
  12. }
  13. You can't be sure your object will *always* have a title when the bundle will want to convert it to a string.
  14. So in order to avoid any fatal error, you must return an empty string (or anything you prefer) for when the title is missing, like this :
  15. .. code-block:: php
  16. public function __toString()
  17. {
  18. return $this->getTitle() ?: '';
  19. }
  20. .. _`__toString`: http://www.php.net/manual/en/language.oop5.magic.php#object.tostring
  21. Large filters and long urls problem
  22. -------------------
  23. If you will try to add hundreds filters to single admin class, you will get a problem - very long filter form url generated.
  24. In most cases you will get server response like *Error 400 Bad Request* OR *Error 414 Request-URI Too Long*. According to
  25. http://stackoverflow.com/questions/417142/what-is-the-maximum-length-of-a-url-in-different-browsers
  26. "safe" url length is just around 2000 characters.
  27. You can fix this issue by adding simple JQuery code on your edit template
  28. .. code-block:: javascript
  29. $(function() {
  30. // Add class 'had-value-on-load' to inputs/selects with values.
  31. $(".sonata-filter-form input").add(".sonata-filter-form select").each(function(){ if($(this).val()) { $(this).addClass('had-value-on-load')}})
  32. // REMOVE ALL EMPTY INPUT FROM FILTER FORM (except inputs, which has class 'had-value-on-load')
  33. $(".sonata-filter-form").submit(function() {
  34. $(".sonata-filter-form input").add(".sonata-filter-form select").each(function(){ if(!$(this).val() && !$(this).hasClass('had-value-on-load')) { $(this).remove()}})
  35. });
  36. });