Browse Source

Added code to generate the full path to the image preview

The image entity can't generate the full path as it doesn't know the location of the web directory.
Kate 11 năm trước cách đây
mục cha
commit
380a8ae690

+ 4 - 0
Resources/doc/cookbook/recipe_image_previews.rst

@@ -56,6 +56,10 @@ we are manipulating form fields we do this from within ``ImageAdmin::configureFo
             // use $fileFieldOptions so we can add other options to the field
             // use $fileFieldOptions so we can add other options to the field
             $fileFieldOptions = array('required' => false);
             $fileFieldOptions = array('required' => false);
             if ($image && ($webPath = $image->getWebPath())) {
             if ($image && ($webPath = $image->getWebPath())) {
+                // get the container so the full path to the image can be set
+                $container = $this->getConfigurationPool()->getContainer();
+                $fullPath = $container->get('request')->getBasePath().'/'.$webPath;
+            
                 // add a 'help' option containing the preview's img tag
                 // add a 'help' option containing the preview's img tag
                 $fileFieldOptions['help'] = '<img src="'.$webPath.'" class="admin-preview" />';
                 $fileFieldOptions['help'] = '<img src="'.$webPath.'" class="admin-preview" />';
             }
             }