forked from sonata-project/SonataAdminBundle
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
42 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
Troubleshooting | ||
=============== | ||
|
||
The toString method | ||
------------------- | ||
|
||
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. | ||
Take care to never return anything else than a string in this method. | ||
For example, if your method looks like that : | ||
|
||
.. code-block:: php | ||
public function __toString() | ||
{ | ||
return $this->getTitle(); | ||
} | ||
You can't be sure your object will *always* have a title when the bundle will want to convert it to a string. | ||
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 : | ||
|
||
.. code-block:: php | ||
public function __toString() | ||
{ | ||
return $this->getTitle() ?: ''; | ||
} | ||
.. _`__toString`: http://www.php.net/manual/en/language.oop5.magic.php#object.tostring |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters