Skip to content

Commit

Permalink
Changed the methods in order to getAbsolutePath returns the full path…
Browse files Browse the repository at this point in the history
… (because it's needed when unlink()
  • Loading branch information
tristanbes committed Jul 20, 2011
1 parent 24a1f96 commit 8bef86b
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions cookbook/doctrine/file_uploads.rst
Original file line number Diff line number Diff line change
Expand Up @@ -48,18 +48,23 @@ First, create a simple Doctrine Entity class to work with::
*/
public $path;

public function getFullPath()
public function getAbsolutePath()
{
return null === $this->path ? null : $this->getUploadRootDir().'/'.$this->path;
}

public function getWebPath()
{
return null === $this->path ? null : $this->getWebLocation().'/'.$this->path;
return null === $this->path ? null : $this->getWebPath().'/'.$this->path;
}

protected function getUploadRootDir()
{
// the absolute directory path where uploaded documents should be saved
return __DIR__.'/../../../../web/'.$this->getWebLocation();
return __DIR__.'/../../../../web/'.$this->getUploadDir();

This comment has been minimized.

Copy link
@rjmunro

rjmunro May 24, 2013

Is there not something better than ../../../.. that can be used here? Like injecting the kernel root or using the assetic assets path?

This comment has been minimized.

Copy link
@stof

stof May 24, 2013

Member

this is exactly why the entity should not be responsible for the whole logic: you cannot inject the kernel root dir cleanly in it.

This comment has been minimized.

Copy link
@weaverryan

weaverryan May 28, 2013

Member

Yes, this entry is not done correctly - se #2346 - we're working on getting it updated :). This should be handled by some external service, where you inject %kernel.root_dir% into it.

}

protected function getWebLocation()
protected function getUploadDir()
{
// get rid of the __DIR__ so it doesn't screw when displaying uploaded doc/image in the view.
return 'uploads/documents';
Expand Down

0 comments on commit 8bef86b

Please sign in to comment.