Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Added another method in order to prevent the document/image not being…
… displayed because of the rendered path with DIR. I tryed to make it as clean as possible.
  • Loading branch information
tristanbes committed Jul 18, 2011
commit 9cf971e51d860507724756d373f145f72abae4d3
10 changes: 8 additions & 2 deletions cookbook/doctrine/file_uploads.rst
Original file line number Diff line number Diff line change
Expand Up @@ -50,13 +50,19 @@ First, create a simple Doctrine Entity class to work with::

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

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

protected function getRealLocation()
{
// get rid of the __DIR__ so it doesn't screw when displaying uploaded doc/image in the view.
return '/uploads/documents';
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you should not add the leading slash here otherwise the rendered link when using asset() in a template will always be /uploads/... even when your app is not at the root of the domain.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@stof yeah but having the app at the top of the domain and not using a leading slash result in the image not rendering. Where this leading slash should be added so ? in the template ?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As I said on the previous PR, you need to use the asset() function in your template to make your app portable.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok thanks, just pushed the modifications. I've just tested and you are right using asset() automatically adds the missing leading slash when it's needed.

}
}

Expand Down