GithubHelp home page GithubHelp logo

Comments (6)

stof avatar stof commented on May 27, 2024

Check your entity: you are not returning a string in the __toString method of your class which is invalid. It has nothing to do with any bundle but with your own code.

from sonataadminbundle.

saptaru avatar saptaru commented on May 27, 2024

Hi,
This is what I actually have in my entity :

MyEntity:
public function getSchemaType() {
// if($this->schemaType){
return $this->schemaType;
// }else{
// return 'none';
// }
}

SchemaTypes Entity:
public function __toString() {
return $this->schemaName;
}

If myEntity has a schemaType defined then the name is present in my Admin List otherwise the catchable fatal error is present.

The same thing happens for MyEntity that is nested and doesn't have a parent define ( I am trying to show the parent name in my list ).

One more thing, may this be important, if I uncomment the code above from getSchemaType() I get an error :
Item "id" for "none" does not exist in SonataAdminBundle:CRUD:list_orm_many_to_one.html.twig at line 16

Thank you for your time !

from sonataadminbundle.

stof avatar stof commented on May 27, 2024

__toString fails because you return null when the property is not initialized.

what is $this->schemaType ? The property mapped for the relation ? In this case, it is normal that it fails. An empty relation returns null (as there is nothing for this relation), not 'none' which is a PHP string.

from sonataadminbundle.

saptaru avatar saptaru commented on May 27, 2024

Yes it is the property mapped for the relation:

/**
* @Orm:ManyToOne(targetEntity="SchemaTypes")
* @Orm:JoinColumn(name="schematype_id", referencedColumnName="id")
*/
private $schemaType;

And the schemaName is the title of the SchemaType which I want it displayed.
Here is the code I have in my MyEntityAdmin class for the $list :

protected $list = array(
'title',
'schemaType',
//..
);

How can I avoid having these errors, considering that I want to display something custom like 'none' without/or with a custom url where no relation is present ?

Cheers,
Cezar

from sonataadminbundle.

stof avatar stof commented on May 27, 2024

don't return 'none' in the getSchemaType() method. Return it in __toString when $this->schemaType is null

from sonataadminbundle.

saptaru avatar saptaru commented on May 27, 2024

Thanks!

from sonataadminbundle.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.