I'm using following code to display an image with CodeIgniter framework.
<?php echo img('sample/logo.png'); ?>
And this is producing following output::
<img alt="" src="http://localhost:8080/test/css/sample/logo.png">
Why it does not closes the tag with />
Also, how can i specify the alt text when i echo image?
thanks
According to user guide, it should end with />. I tried it out, and it works.
If you want a shorter tag, use this:
<?php echo img(array('src'=>'image/picture.jpg', 'alt'=> 'alt information')); ?>
Sometimes if you view source using certain browsers (firefox, chrome), it omits the /> tag. Try view source using a notepad or something, it should display proper /> tag.
$image_properties = array(
'src' => 'sample/logo.png',
'alt' => 'Me, demonstrating how to eat 4 slices of pizza at one time',
'class' => 'post_images',
'width' => '200',
'height' => '200',
'title' => 'That was quite a night',
'rel' => 'lightbox',
);
img($image_properties);
// <img src="http://site.com/index.php/sample/logo.png" alt="Me, demonstrating how to eat 4 slices of pizza at one time" class="post_images" width="200" height="200" title="That was quite a night" rel="lightbox" />
reference : http://codeigniter.com/user_guide/helpers/html_helper.html#img
Dont echo an image like that, do it like this:
echo "<img src='sample/logo.png' alt='my company name' title='my company logo' border='0' />";
Remeber the location you have there is relative, you should try to stick to absolute paths were possible eg: "/test/css/sample/logo.png" to avoid confusion.
(sorry, missed the bit where you said you were using a framework).
Related
In yii2 basic ActiveForm i have added a drop-down list and in it used the "options" array to add my attributes .i want to add select2 in my drop-down but it is not working .i have searched on web and found this method of "options" array i have used below but still its showing no output in the view
<div class="col-xs-6 col-lg-6">
<div class="form-group form-material floating" data-plugin="formMaterial">
<div class="example"> <b role="presentation"></b>
<?= $form->field($model, 'corporation_status')->dropDownList(Yii::$app->appstatues->status,['options'=>['class'=>'form-control','prompt'=>'abc','data-plugin'=>'select2']])->label('Stat'); ?>
</div>
</div>
</div>
Any help would be much appreciated.
Use extension https://github.com/kartik-v/yii2-widget-select2
many good extensions is there too:
http://demos.krajee.com/
Found the solution for "select2" to be added to your drop-down list do the following steps:
Add following css and js files to your "AppAsset":
https://cdnjs.cloudflare.com/ajax/libs/select2/4.0.3/css/select2.min.css
https://cdnjs.cloudflare.com/ajax/libs/select2/4.0.3/js/select2.min.js
and in the form field add 'data-plugin'=>'select2' like this:
<?= $form->field($model, 'corporation_status')->dropDownList(Yii::$app->appstatues->status,['prompt' => 'hello','data-plugin'=>'select2','class'=>'form-control'])->label('Status'); ?>
Run this command to install kartik\select2 widget for yii2
php composer.phar require kartik-v/yii2-widget-select2 "#dev"
Then to use the widget.
//Include kartik\select2 Class
use kartik\select2\Select2;
// Normal select with ActiveForm & model
echo $form->field($model, 'corporation_status')->widget(Select2::classname(), [
'data' => Yii::$app->appstatues->status,
'options' => ['prompt' => 'Select a state ...'],
'pluginOptions' => [
'allowClear' => true
],
]);
I'm developing a backend component for Joomla and when I access certain views of my component the notice below gets logged. I'm currently running Joomla 3.5.1. Has anyone got the same notice?
PHP Notice: Undefined index: doTask in /var/www/html/layouts/joomla/toolbar/popup.php on line 14
The reason for the notice was that I created a popup button like this:
$layout->render(array('name' => 'print', 'text' => JText::_('BUTTON_PRINT'), 'class' => 'icon-print'));
Adding doTask parameter fixed the problem and the notice is not showing anymore.
$layout->render(array('name' => 'print', 'doTask' => '', 'text' => JText::_('BUTTON_PRINT'), 'class' => 'icon-print'));
I looked at the popup.php file and after that it was pretty easy to figure out the cause. As you can see $doTask variable is used every time when a popup button is rendered.
<button value="<?php echo $doTask; ?>" class="btn btn-small modal" data-toggle="modal" data-target="#modal-<?php echo $name; ?>">
I have images saved in /web/uploads/PROJECT in Yii2. How do i display them on page? below is my codes but its broken link image.
Controller:
$img = Yii::$app->request->baseUrl.'/web/uploads/PROJECT/';
$image = Html::img($img.$img_obj['AVATAR'],["width"=>"600px"]);
View:
echo $data;
Do i have to set any rights to display it? Right-clicking and opening image in new tab shows the url "/web/uploads/PROJECT/3fioobapJ5vRk_wdCEzDJbQWyO66inWO.jpg" which seems to be correct but page displays "Not Found (#404)"
Can anyone kindly advise? Thanks!
Strangely, using the below codes displays the images correctly.
$img = Url::to('#web/uploads/PROJECT/').$img_obj['AVATAR'];
$image = '<img src="'.$img.'" width="600" />';
<img src="<?= Yii::$app->request->baseUrl . '/backend/web/uploads/' . $model->profile_photo ?>" class=" img-responsive" >
<?php echo Html::img('#web/img/icon.png', ['class' => 'pull-left img-responsive']); ?>
The static images should be placed inside web/any_folder_name
to access in YII 2:
<?= Html::img('#web/any_folder_name/bg1.jpg', ['alt'=>'some', 'class'=>'thing']);?>
Add this code in your Grid View:
[
'attribute'=>'photo',
'value' => Html::a(Html::img(Yii::getAlias('#web').'/image/'.$st_data->photo, ['alt'=>'some', 'class'=>'thing', 'height'=>'100px', 'width'=>'100px']), ['site/zoom']),
'format' => ['raw'],
],
So from the product view i am getting related products to display. For reasons i wont get into i need to display the image of the related product but it has to be a custom image attribute. So i have created a custom image attribute called colour_swatch and i need to access it and display it on screen. I have done some reading on the issue and have not managed to find a solution to fit my needs.
So here is my code:
<?php foreach($this->getItems() as $_item): ?>
<div class="eachProductRelated">
<a href="<?php echo $_item->getProductUrl() ?>" title="<?php echo $this->htmlEscape($_item->getName()) ?>" class="product-image">
<img src="<?php echo $this->helper('catalog/image')->init($_item, 'colour_swatch') ?>"
width="20px" alt="<?php echo $this->htmlEscape($_item->getName()) ?>"/>
</a>
</div>
<?php endforeach ?>
If we replace colour_swatch with small image that of course will work. I have read that you can't access a custom image attribute if you aren't calling it directly from the product view. And a lot of the solutions i have seen seem to be massively overkill, Surely there is a simpler solution???
Might be worth telling you that i get the following error message:
a:5:{i:0;s:25:"Image file was not found.";i:1;s:4015:"#0
/Users/Frank/Sites/bosideng/app/code/core/Mage/Catalog/Helper/Image.php(163):
Mage_Catalog_Model_Product_Image->setBaseFile(NULL)
Is it possible that i have to do some kind of if no_selected check ?
I have figured out this issue and pardon my French but it was a ridiculous and a stupid oversight by Magento.
When setting up your new custom image attribute you must set 'Use In Product Listing' to yes in the drop down before you select the attribute type 'Media Image' because guess what!? When you select Media Image, Magento hides that option.
Credit to this guy whose post i found after ages of searching: http://thedistance.co.uk/journal/2011-10/missing-magento-media-images
Hello i think you add new image url in custom image attribute then call may be help you
<img src="<?php echo Mage::getModel('catalog/product')->load($product)->getData('colour_swatch'); ?>"
For those of you creating custom image type using installer, add the following to make image visible on both listing and view pages:
$this->addAttribute(Mage_Catalog_Model_Product::ENTITY, 'colour_swatch', array(
'group' => 'Images',
'type' => 'varchar',
'frontend' => 'catalog/product_attribute_frontend_image',
'label' => 'Color Swatch',
'input' => 'media_image',
'class' => '',
'source' => '',
'global' => Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_STORE,
'visible' => true,
'required' => false,
'default' => '',
'used_in_product_listing' => true,
));
If Flat Catalog Category and Use Flat Catalog Product is set to Yes, then you can add the specific attributes to the collection
Like
$collection = Mage::getResourceModel('catalog/product_collection');
$collection->addAttributeToSelect('*');
$collection->addAttributeToSelect('attributes_name');
This is working perfect for me
I have a number of jpg files within the images folder of my custom themes that are linked to a template. I can't see what is wrong but the images are appearing broken. I can only imagine I have the file path wrong:
<img src="images/leads.jpg" width="176" height="58" alt="leads" />
Similarly, I am trying to link images dynamically to the custom fields set on the relevant WP back-end page and nothing is appearing. I am using the following code in the template:
<img src='<?php echo get_post_meta($post->ID, 'sales', true); ?>' />
I have tried to link this to to the page "images/sales.jpg" in the custom field.
Many thanks in advance.
You must get the template_url first.
<img src="<?php echo get_bloginfo('template_url').get_post_meta($post->ID, 'sales', true); ?>/images/lead.jpg" width="176" height="58" alt="leads" />
In your theme, all the paths must be refereed as absolute paths. Try:
<img src='<?php echo get_stylesheet_directory_uri() . get_post_meta($post->ID, 'sales', true); ?>' />
How about this?
<img src='<?php echo get_stylesheet_directory_uri() '.images/.' . get_post_meta($post->ID, 'sales', true); ?>' />