Yii2 : Show image from Folder Common - image

I have a picture in folder common that i want to show in view, but it doesn't shown.
My code is :
<img src="<?= Yii::$app->request->baseUrl . '/common/web/img/ava.jpg' ?>" class=" img-responsive" >
It's generated to be <img src="/simdsm/common/web/ava.jpg" class=" img-responsive"> but the image does not appear.
How to fix it?

Since no one actually posted an example of using assets to access files saved in a backend-folder or the other way around, it's quite simple:
Let's say you are working with the yii advanced template and you have a backup/web/uploads/ folder in which you save images uploaded via your backend. Now you'd like to display those images on your frontend. Since the Frontend-App and the Backend-App are two seperate Applications, they don't know of each other.
You create a new asset in your frontend/assets/, let's call it BackendAsset.php:
<?php
namespace frontend\assets;
use yii\web\AssetBundle;
class BackendAsset extends AssetBundle {
public $sourcePath = '#backend/web/uploads';
}
where $sourcePath is the backend-folder (source) you'd like to access on the frontend. The #backend alias is predefined in the advanced template, so we'll use it.
Now in our view we can simply use the BackendAsset:
<?php
use frontend\assets\BackendAsset;
$backend = BackendAsset::register($this);
?>
and now we can easily display a file, let's say backend/web/uploads/somefile.jpg:
<img src="<?= $backend->baseUrl . '/somefile.jpg' ?>" >
NOTE: Using the asset in this way copies all the files from the backend/web/uploads to an asset folder in the frontend. To prevent that, you can tell your application not to copy the files, but to link to them (creating SymLinks) instead, using linkAssets (yii2 docu):
In your app configuration (in this case frontend/config/main.php), set the linkAssets parameter to TRUE:
'components' => [
'assetManager' => [
'linkAssets' => true,
]
]

In case of using advanced application template, images should be placed in these web accessible folders - frontend/web or backend/web.
Also usually I create alias from frontend/web/images to backend/web/images to display images in backend from frontend.
What you mentioned is not web accessible directory.
Alternative way to publish images from such directory will be creating asset bundle for that folder, that way images will be copied in frontend/web/assets for example. You can read more about asset bundles in official docs.

We can do it easily by simple step of below
In common/config/params-local.php
Yii::setAlias('#imageurl', 'http://localhost/project_name/backend/web/');
in above example i have my image under backend/web/images/product_images
In frontend, i am getting like,
<img src="<?php echo Yii ::getAlias('#imageurl'); ?>/images/product_images/<?= $product['image']?>" alt=" " class="img-responsive" />
it's simply working for me...

Related

How To Emit Only Gallery IMGs from Batflat CMS

If you make a Gallery in Batflat CMS, the template tag it creates will generate its only Bootstrap HTML for a gallery. What if I just want to emit IMG tags for the gallery items, instead?
Create a Gallerymod custom module. That way, your customization may likely survive a Batflat Update.
Copy inc/modules/galleries as inc/modules/gallerymod.
Remove the lang folder and Admin.php in your gallerymod folder.
Change the Name and Description inside the gallerymod/Info.php, as well as the comments. I used static strings instead of code. Also in this file, inside the install function and uninstall function, remove code inside those so that it does nothing on install or uninstall.
In your gallerymod/Site.php, look for the $assign[$gallery['slug']] assignment, and on the following line, add:
$assign[$gallery['slug'] . '-alt1'] = $this->draw('gallery-alt1.html', ['gallery' => $tempAssign]);
Also, where you have the namespace line set as namespace Inc\Modules\Galleries;, change it to namespace Inc\Modules\Gallerymod;.
In your gallerymod/view folder, create a gallery-alt1.html file and add these contents:
{loop: $gallery.items}
<img class="photo-{if: $value.title}{$value.title}{/if}" alt="" class="img-responsive" src="{?=url($value.src.lg)?}">
{/loop}
Now activate this inactive module in Batflat's admin system. You'll notice that it has no admin panel -- because it doesn't need one. You already have the Galleries one. Do not deactivate the Galleries module because the Gallerymod module relies on the Galleries module.
Now, from your custom theme template, you can call this by varying how you called the old slug. So, if your old way of calling the gallery was something like {$gallery.home-photos}, then you would merely tack on the "-alt1" on the end and call it like {$gallery.home-photos-alt1}. I like to wrap these in a DIV wrapper with an ID on it so that I can address it with CSS, jQuery, or Javascript.
In the Batflat Admin system, go back and edit your image titles in the gallery. Treat those titles like a slug (lowercase alphanumeric phrase with dashes) because these are used as class names on the IMG tags in gallery-alt1.html, and you may want to address these individually in CSS, jQuery, or Javascript, later on.
Refresh your browser and you may see the source code display something similar to:
<div id="hidden-images" class="hidden">
<img class="photo-man2" alt="" class="img-responsive" src="https://example.com/uploads/galleries/2/15831273220.jpg">
<img class="photo-woman1" alt="" class="img-responsive" src="https://example.com/uploads/galleries/2/15831272980.jpg">
<img class="photo-man1" alt="" class="img-responsive" src="https://example.com/uploads/galleries/2/15831272540.jpg">
</div><!-- hidden-images -->
Just remember that if you update your version of Batflat, that you may need to reapply this customization again -- it depends on what was done in the update to the existing Galleries module.
If you have different tastes as to how you want to format your images, just edit your gallery-alt1.html file. Plus, you can make multiples of these for different situations, such as gallery-alt2.html, gallery-alt3.html, etc. You can even make it emit JSON instead of html so that you can insert it into a Javascript block in your theme.
Another tip for debugging, in case your site won't load or the admin system breaks, is to edit inc/core/defines.php and change the DEV_MODE to false. That way, PHP will show you every error and that might help you in debugging what might be wrong.

How to show image form another folder in laravel 5.2

I want to show picture form another folder. But why it's not working?
<img src="/picture/Capture.JPG" style="width:600px;height:400px">
My folder name is picture and image name is Capture.JPG
To print images ,css and js files correct path laravel have a default function asset()
Try this
<img src="{{ asset('picture/Capture.jpg') }}" style="height:400px;width:400px" >
I find my solution last night.
At first i create a folder in public folder name images. Then i store the picture. And the code formet is here.
<img src="{{url('/images/6.JPG')}}" alt="Image"/>

how to display images form a folder inside another folder laravel 4

I am trying to display images from a database through folder. I have a folder. Albums, and inside that more folders ("home", "school"). I'm saving images into "Album/home/a.jpg". I want to display images from folder ../home.. (eg: Album/home/a.jpg)
I used this code:
<a rel="prettyPhoto[pp_gallery]" class="thumbnail" href="{{URL::asset('/Albums/'.$gallery->galimg)}}" width="100%" height="100%" >
<img src="{{URL::asset('/Albums/'.$gallery->galimg)}}" width="100%" height="100%"/> </a>
but it's not working {{URL::asset('/Albums/'.$gallery->galimg)}} only see gallery place (one square) not image..
how to solve it??
I think you have to take care of few things.
Make sure that the folder Albums is located inside the public folder directly if not reference it.
Check the database whether you are storing just image name or full path or may be there is no extension of images on db.
No need to use URL facade. There is asset method which you can use directly ( specific in Laravel4.* ) like this {{ asset($gallery->image) }}

Modifying joomla mod_banner to count banner

I'm using default joomla mod_banner.
I'd like to modify the module so can give specific css class for each banner image, so if the module displaying 3 banner images, the first banner (image) will have class="banner1", the second image will have class="banner2" the third image will have class="banner3" and so on.
How can I do that?
If you decide to modify your mod_banners module, then just follow the steps:
Open the /modules from your root directory.
Find the directory named mod_banners in modules/mod_banners
Find out the tmpl directory modules/mod_banners/tmpl
default.php is the file that display the images into the frontend of you joomla website.
just edit this file. See the img tag into and just change whatever name you want to give the class..
UPDATE : Take a look on the given Codes:
// Add variable before
$unique_number = 1;
// Provide the Provides the images URL or related information
foreach($list as $item):
now just find out the <img tag and just add a class something like
<img class='banner-<?php echo $unique_number?>'
and at the end of the file findout the endforeach; and just add the code something like
<?php
$unique_number++;
endforeach;
?>
providing you the class name like banner-1, banner-2, .... etc.
IMPORTANT: If you notice on the top most of your default.php the module provide the images into an array, If you are familiar with the Joomla modules structures then you can modify it easily.

How do I separate the files for 'widgets' in codeigniter?

I have a basic cms that loads content into pages that have mustache tags to indicate where in the html code those contents will appear.
The contents are specified in a widget model which indicate which type of content is to be displayed, so for example, freetext with id. or another model and id. each one of those models will be displayed differently based on the model they are based on.
I can imagine this becoming and bit unwieldy, is there a way to have a separate folder to put those widgets in so that it doesn't clutter my main code.
Something like apotomo does on rails would be good, but for codeigniter.
A widget model? That is not so nice. Have you tried looking at PyroCMS?
https://github.com/pyrocms/pyrocms/blob/master/system/pyrocms/modules/widgets/libraries/Widgets.php
From the sound of it you may be more interested in our Plugins library (sounds like the same thing with a different name). It is set up with a MY_Parser and runs on top of Dan Horrigan's Simpletags implementation.
Either way this has all be done plenty. If you want some more specific tailored advice you might have to demo some of your code.
Create a folder inside application/views called widgets. Put your widgets inside that folder and create a separate file for each widget (d0h).
Next, you have 2 options (at least that i know of):
a.) Load the widgets into variables inside the controller, then pass them to the main/general view
$data['widget_twitter_feed'] = $this->load->view('widgets/twitter', '', false);
$data['widget_something'] = $this->load->view('widgets/something', '', false);
$this->load->view('my_main_view', $data);
b.) Load the widgets inside the main/general view itself
<html>
...
<div id="sidebar">
<?php $this->load->view('widgets/twitter'); ?>
</div>
...
<div id="footer">
<?php $this->load->view('widgets/something'); ?>
</div>
...
</html>

Resources