php - Doctrine FIxtures and Symfony2 Request scope -
i want create article fixtures project uses doctrine2 , symfony 2.2.
here how articles created:
they don't link images directly instead contain image names. before saving article articlemanager
parses article text, finding image names, searching images in database , replacing image markup part real image path, example.
this article content typed in form , contains ![image description](here awesome image name)
then when form submitted , articlemanager->save($article)
called, article manager changes image markup real file web path:
this article content typed in form ![image description](/path/to/my_awesome_image.png)
the problem: articlemanager
relies on assetic assets helper
service build full web image paths , service resides in request
scope. on other hand, doctrine fixtures
ran cli can't access service, making me unable image paths when loading article fixture.
can suggest me least hackish way of tackling problem?
ok, @cheesemacfly's comment digged bit , realized since images stored in public folder don't have use assetic @ all!
instead of using create image urls injected router
service articlemanager
, generated urls way:
$baseroute = $this->router->getcontext()->getbaseurl(); $appfiles = array('/app.php', '/app_dev.php'); $baseroute = str_replace($appfiles, '', $baseroute); $imagedocumentroute = $baseroute . '/' . $imagedocument->getwebpath();
imagedocument->getwebpath()
returns image name appended subfolder images saved. e.g. subweb/path/imagename.png
.
Comments
Post a Comment