I have many images in backends web folder, I want to use those images in frontend how to get those files?
I need to display 1 (first) image which path is saved in database like Img1.jpg;img2.jpg;
<?php
foreach (explode(';',rtrim($row['images'],';'),1) as $key_img => $value_img)
{
?>
<?php echo Html::img('#backend/web'.'/'.$value_img);?>
<?php
}
?>
<?= \yii\helpers\Html::img('#backend/web/images/your-image.jpg') ?>
The src parameter, containing the backend alias, will be processed by Url::to()
Check the docs for details on Html::img().
Simply try:
<?= \yii\helpers\Html::img( Yii::getAlias('#backend'). '/web/images/your-image.jpg') ?>
Related
I tried to make a dropdown list in yii2 using this link : How to make a drop down list in yii2?
my code is :
<?php use yii\helpers\ArrayHelper;
use app\models\Product;
?>
<?= $listdata=ArrayHelper::map(Product::find()->all(),'id','name'); ?>
<?= $form->field($model, 'parent_id')-> dropDownList($listdata); ?>
but I have a problem in line of using ArrayHelper
the problem is:
PHP Notice – yii\base\ErrorException
Array to string conversion.......! I tested the below code :
$listData=ArrayHelper::map(Product::find()->asArray()->all(),'id','name');
but it dos not solved and has the same error!
whats the problem? can somebody help me?
You are trying to echo an array, change <?= to <?php in:
<?= $listdata=ArrayHelper::map(Product::find()->all(),'id','name'); ?>
Try like this
<?php
use yii\helpers\ArrayHelper;
use app\models\Product;
?>
<?= $form->field($model, 'parent_id')->dropDownList(
ArrayHelper::map(Product::find()->all(),'id','name'),
['prompt'=>'Select '])
?>
How do I change the header after login, or is using another header even the right way to do it? Meaning there would be two different headers(guest/user). I've searched for it, mostly about redirects of the entire page, not what I am looking for.
Sorry for the noob question. :/
Make two files in your view with guest_header.php and user_header.php when user is logged in user user_header.php as your header file in your layout or simply use guest_header.php
and in your column layout use it like below
when user is logged in
<?php if(Yii::app()->user->id): ?>
<?php $this->beginContent('//layouts/user_header.php'); ?>
when user is guest
<?php else: ?>
<?php $this->beginContent('//layouts/guest_header.php'); ?>
<?php endif; ?>
Added this line
<?php $this->endContent(); ?>
<?php $this->beginContent('//layouts/main'); ?>
<?php echo $content; ?>
</div><!-- content -->
<?php $this->endContent(); ?>
hopefully a quick question here, have not been able to find out the answer on google. Anyway I have the following File upload field.
<div class="row">
<?php echo CHtml::form('', 'post', array('enctype' => 'multipart/form-data')); ?>
<?php echo $form->labelEx($model, 'doc'); ?>
<?php echo CHtml::activeFileField($model, 'doc'); ?>
<?php echo $form->error($model, 'doc'); ?>
</div>
The question I have is how to change the default text? On the page in question the upload field comes up with "No file chosen" beside the button when the page loads. I wish to change this text, anyone tell me how? Thanks.
I quick & dirty fix is this:
<?php echo CHtml::activeFileField($model, 'type',array('style'=>'width:100px;', 'onchange' => 'this.style.width = "100%";')); ?>
I would like to link to a different controller, passing in multiple parameters.
Documentation:
http://www.yiiframework.com/wiki/48/by-example-chtml/
<?php echo CHtml::link('Link Text',array('controller/action',
'param1'=>'value1',
'param2'=>'value2',
'param3'=>'value3')); ?>
<?php echo CHtml::link('Link Text',
Yii::app()->createUrl('controller/action',array(
'param1'=>'value1',
'param2'=>'value2',
'param3'=>'value3')); ?>
I have 10 pages, 4 of which should be accessible by logged in users.
Is there a plugin that exists to password protect these pages? Ideally, you can login once and then subsequently view all these protected pages.
I have Googled a bit, but haven't been able to find something that lets you protect individual pages, only the entire WordPress platform.
Does something like this exist, and if there are multiple, which is the best in your experience?
Thanks
You could use a Membership Plugin. Most of them cost money. A Google search turned up a free one called MemberWing, but I haven't tried it and can't speak to how good it is.
Generally a membership plugin will handle registration and access control. If you decide that's overkill, you could focus just on content protection with a Custom Page Template. Below, I've attached a generic WordPress Page Template that will hide content from guests. It's based off of WordPress' old default theme. If the user is not logged in, it'll display a message telling them they can't access the content as a guest.
<?php
/*
Template Name: Protected Content
*/
get_header(); ?>
<div id="content" class="narrowcolumn" role="main">
<?php if (have_posts()) : while (have_posts()) : the_post(); ?>
<div class="post" id="post-<?php the_ID(); ?>">
<h2><?php the_title(); ?></h2>
<div class="entry">
<?php
if(is_user_logged_in()) {
the_content('<p class="serif">Read the rest of this page »</p>');
}
else {
echo "You must be logged in to access this content!";
}
?>
<?php wp_link_pages(array('before' => '<p><strong>Pages:</strong> ', 'after' => '</p>', 'next_or_number' => 'number')); ?>
</div>
</div>
<?php endwhile; endif; ?>
<?php edit_post_link('Edit this entry.', '<p>', '</p>'); ?>
<?php comments_template(); ?>
</div>
<?php get_sidebar(); ?>
<?php get_footer(); ?>
Private posts should do what you want. You shouldn't need a plugin.