Reputation: 2837
While uploading a file, I'm trying to check if a directory exists.
If it doesn't exists, then I make the directory.
Directory name basis is the entity name plus is id
(entity-id)
if(!is_dir($this->myDir.'entity-'.$object->getParent())) {
mkdir($this->myDir.'entity-'.$object->getParent());
}
myDir
is : %kernel.root_dir%/../web/upload/myDir/
in app/config/config.yml
$object
is the object I passed to my function, it contain the data from the submited form.id
The problem is that data from the form send the parent
parameter as a __toString
of it's id
How can I revert this to the parent id
?
Upvotes: 2
Views: 69
Reputation: 454
I guess that getParent() is not __toString
, but it looks like it, because you try to concatenate it with the 'entity-' string. Therefore you have given object there, so you can access the id with the standard getter (e.g. getId() method)
So the parent object's id should be returned by $object->getParent()->getId()
Upvotes: 3