I am trying to implement a image gallery in cakephp with below structure:
echo $this->Html->link(
$this->Html->image('gallery/fashion/fashion-photography-guwahati-'.$i.'.jpg',
array('class'=>'img img-responsive')
),
'gallery/fashion/fashion-photography-guwahati-big-'.$i.'.jpg',
array(
'class' => 'col-sm-4',
'escape' => false,
'data-toggle' => 'lightbox',
'data-gallery' => 'multiimages',
)
);
But the above script outputs HTML:
<a href="/nitish/cakem/galleries/gallery/fashion/fashion-photography-guwahati-big-4.jpg" class="col-sm-4" data-toggle="lightbox" data-gallery="multiimages">
<img src="/nitish/cakem/img/gallery/fashion/fashion-photography-guwahati-4.jpg" class="img img-responsive" alt="" />
</a>
As you can see in the anchor path, additional galleries directory is added. How to remove this ?
NB: galleries is my controller name
Strart you paths with a slash:
echo $this->Html->link(
$this->Html->image('/gallery/fashion/fashion-photography-guwahati-'.$i.'.jpg',
array('class'=>'img img-responsive')
),
'/gallery/fashion/fashion-photography-guwahati-big-'.$i.'.jpg',
array(
'class' => 'col-sm-4',
'escape' => false,
'data-toggle' => 'lightbox',
'data-gallery' => 'multiimages',
)
);
Related
How can i add anchor class in codeigniter
This is normal html tag:
<a class="tooltips" href="index.html"><span>Log out</span><i class="lnr lnr-power-switch"></i></a>
But when i add class="tooltips" it comes out of a tag:
<?php echo anchor('User_Controller/settings','class="tooltips"<span>Logout</span><i class="lnr lnr-power-switch"></i>');?>
This is what i get:
class="tooltips"<span>Logout</span><i class="lnr lnr-power-switch"></i>
You have syntax error, you can try this ,
<?php echo anchor('User_Controller/settings', '<span>Logout</span><i class="lnr lnr-power-switch"></i>', 'class="tooltips"'); ?>
for refference : Ancher helper
$atts = array(
'width' => 800,
'height' => 600,
'scrollbars' => 'yes',
'status' => 'yes',
'resizable' => 'yes',
'screenx' => 0,
'screeny' => 0,
'window_name' => '_blank'
'class' => 'btn btn-primary'
);
echo anchor('news/local/123', 'Click Me!', $atts); //it's example
I want to know that how to write the below given html code in cakePHP 3 syntax :-
<a href="#" class="sidebar-toggle" data-toggle="push-menu" role="button">
<span class="sr-only">Toggle navigation</span>
</a>
you can simply put the span tag inside the html link this way
<?= $this->Html->link(
'<span class="sr-only">Toggle navigation</span>',
'#', [
'class' => "sidebar-toggle",
'data-toggle' => "push-menu",
'role' => "button",
'escape' => false
]); ?>
or you can use the tag method to create the span tag
<?= $this->Html->link(
$this->Html->tag('span', 'Toggle navigation', ['class'=>"sr-only"]),
'#', [
'class' => "sidebar-toggle",
'data-toggle' => "push-menu",
'role' => "button",
'escape' => false
]); ?>
i'm trying without success to add an image inside a Navbar menuItem.
It works fine in the brandLabel
But doesn't work on anoter menu item
(I Want to display the logged user image near his name)
I Tryed several times but doesnt seem to make it work,
Would apreciate your help please...
The Code is this:
<?php $this->beginBody() ?>
<div class="wrap">
<?php
NavBar::begin([
'brandLabel' => Html::img('#themes'.'/siteImages/Logo.jpg', ['alt'=>Yii::$app->name]),
'options' => [
'class' => 'navbar-default navbar-fixed-top',
],
]);
// display Login page to guests of the site
if (Yii::$app->user->isGuest) {
$menuItems[] = ['label' => Yii::t('app', 'Login'), 'url' => ['/site/login'],
'options' => [
'class' => 'navbar-right',
],];
}
else
{
// Show sales content to sales+ users
if ( Yii::$app->user->can('useSalesContent'))
{
$menuItems[] = ['label' => Yii::t('app', 'Sales'),
// 'class' => "pull-left",
'url' => Yii::$app->homeUrl,
'linkOptions' => ['id' => 'sales',
'class' => 'navbar-left',
],
];
// Show Admin content to manager+ users
if (Yii::$app->user->can('useAdminContent'))
{
$menuItems[] = ['label' => Yii::t('app', 'Administration'),
'url' => Yii::$app->homeUrl,
'linkOptions' => ['id' => 'admin'],
'options' => [
'class' => 'navbar-left',
],];
}
// display Logout to logged in users
if (!Yii::$app->user->isGuest) {
$menuItems[] =
[
'label' => Yii::t('app', 'Logout'). ' (' . Yii::$app->user-
>identity->username . ')',
'url' => ['/site/logout'],
'linkOptions' => ['data-method' => 'post']
//****** This is where I want the user image to be shown ****//
];
}
}
// echo navbar with selected items
echo Nav::widget([
'options' => ['class' => 'navbar-nav navbar-right'],
'items' => $menuItems,
]);
NavBar::end();
?>
<div class="container">
<?= Alert::widget() ?>
<?= $content ?>
</div>
endBody() ?>
Provided the user model has an attribute imageUrl it would be accessible through:
Yii::$app->user->identity->imageUrl
This would become something like:
If you would like to add it to the logout button:
$menuItems[] = [ 'encode'=>false, label' => Yii::t('app', 'Logout'). ' (' . Yii::$app->user- >identity->username . ') ' . Html::img(Yii::$app->user- >identity->imageUrl), 'url' => ['/site/logout'], 'linkOptions' => ['data-method' => 'post']];
make sure you include 'encode' => false,
To add it as a separate item (for instance, to give it a different link):
$menuItems[] = [ 'encode' => false, 'label' => Html::image(Yii::$app->user- >identity->imageUrl)];
Edit:
Make sure you include the Html with a use statement in your view, or provide the full namespace declaration with Html class.
Problem in dependent dropdowns when editing in my yii application.
While editing, the drop downs are not automatically selected.
In my view,
array('class' => 'CButtonColumn',
'header' => 'Manage',
'template' => '{update} {view} {delete}',
'htmlOptions' => array('width' => '20%'),
'buttons' => array(
'update' => array(
'label' => '',
'imageUrl' => '',
'options' => array('class' => 'glyphicon glyphicon-pencil'),
),
'view' => array(
'label' => '',
'imageUrl' => '',
'options' => array('class' => 'glyphicon glyphicon-eye-open'),
),
'delete' => array(
'label' => '',
'imageUrl' => '',
'options' => array('class' => 'glyphicon glyphicon-remove'),
),
),
),
<div class="form-group">
<label for="reg_input" class="req">Course</label>
<?php
$course = CHtml::listData(Course::model()->findAll(), 'courseid', 'course_name');
echo CHtml::activeDropDownList($model, 'courseid', $course, array(
'empty' => 'Select Course', 'class' => "form-control",
'ajax' => array(
'type' => 'POST',
'url' => CController::createUrl('Assignment/Fetchbatch'),
'update' => '#' . CHtml::activeId($model, 'batchid'))));
?>
<?php echo $form->error($model, 'courseid', array('class' => 'school_val_error')); ?>
</div>
<div class="form-group">
<label for="reg_input" class="req">Batch</label>
<?php
$batch = CHtml::listData(Batch::model()->findAll(), 'batchid', 'batch_name');
echo $form->dropDownList($model, 'batchid', $batch, array('prompt' => 'Select Batch',
'class' => "form-control",
'ajax' => array(
'type' => 'POST',
'url' => CController::createUrl('Assignment/Fetchsubject'),
'update' => '#' . CHtml::activeId($model, 'subjectid'))));
echo $form->error($model, 'batchid', array('class' => 'school_val_error'));
?>
</div>
Second dropdown get the data, to change of first dropdown. At this condition the dropdown will not be selected automatically. Because when editing, that value is not there. So I fixed this problem, my code is above this.
I'm just learning Yii a few days ago to developer a website for company. Now i have some issue with Yii pagination and i really need your help.
Currently i can make Yii pagination. However, i need to create a button besides pagination area. Everytime, i click that button, it will call ajax to load next page or previous pages (if current page is last page).
Here is my model:
public function getListDesc()
{
$arrPlace = array(0 => '--- --- --- ---');
$criteria=new CDbCriteria;
$criteria->select='t.*,pi.path path';
$criteria->join='JOIN places_images pi ON t.id=pi.places_id';
$criteria->group = 't.id';
$criteria->compare('t.deleted', '<>1', false);
$criteria->compare('t.status',1);
$criteria->compare('outlet','Outlet 1');
$criteria->order = 't.id DESC';
return new CActiveDataProvider('Places', array(
'criteria'=>$criteria,
'pagination' => array(
'pageSize' => 2
)
));
}
Here is a part of my index page which is call that model:
<?php
$this->widget('zii.widgets.CListView', array(
'id' => 'places-list-right',
'dataProvider'=> Places::model()->getListAsc(),
'summaryText'=>'',
'pager' => array(
'header' => '',
'prevPageLabel' => '<<',
'nextPageLabel' => '>>',
),
'itemView'=>'_fea_oulet',)
);
?>
Here is _fea_oulet.php file:
<div class="place_img" id="<?=$data->id?>">
<div class="plusimage">
<a href="javascript:void(0);" onclick="randnew();">
<img alt="<?=$data->id?>" src="<?php echo Yii::app()->request->baseUrl; ?>/images/9life-show-more-images.png" style="border:none;border-radius:0;-webkit-border-radius: 0; -moz-border-radius:0">
</a>
</div>
<?php echo CHtml::image("timthumb.php?src=".$data->path."&w=294&h=294&zc=1&q=100",$data->title);?>
<div class="featitle">
<h3><span><?php
if(strlen($data->title) > 30) {
echo CHtml::encode(mb_substr($data->title,0,30,'UTF-8')) . '...';
}
else{
echo CHtml::encode($data->title);
}
?></span>
<img src="<?php echo Yii::app()->request->baseUrl; ?>/images/9life-show-more-green.png" style="border:none;border-radius:0;-webkit-border-radius: 0; -moz-border-radius:0">
</h3>
</div>
</div>
Any help are appreciates.
Thanks,
You can override CLinkPager class and use your own implementation MyLinkPager in your CListView widget's call specifying its pager property like this:
$this->widget('zii.widgets.CListView', array(
'id' => 'places-list-right',
'dataProvider' => Places::model()->getListAsc(),
'summaryText' => '',
'pager' => array(
'class' => 'MyLinkPager',
'header' => '',
'prevPageLabel' => '<<',
'nextPageLabel' => '>>',
),
'itemView' => '_fea_oulet'
));
run() method of CLinkPager is the place where pager buttons' rendering happens so you can override this method directly. Or you can override createPageButtons() method by adding your custom button to $buttons array if you want to see it along with other page buttons.