Page Layout in Yii2 - yii2

Contents are going under the top Navigation bar. Sometimes it shows right. Sometimes the problem occurs. Please help. Attaching picture of the error page.I am giving my views/layout/main file below. The content of the page is a bit in upward direction.
<?php
/* #var $this \yii\web\View */
/* #var $content string */
use yii\helpers\Html;
use yii\bootstrap\Nav;
use yii\bootstrap\NavBar;
use yii\widgets\Breadcrumbs;
use frontend\assets\AppAsset;
use common\widgets\Alert;
use kartik\sidenav\SideNav;
use yii\helpers\Url;
AppAsset::register($this);
?>
<?php $this->beginPage() ?>
<!DOCTYPE html>
<html lang="<?= Yii::$app->language ?>">
<head>
<meta charset="<?= Yii::$app->charset ?>">
<meta name="viewport" content="width=device-width, initial-scale=1">
<?= Html::csrfMetaTags() ?>
<title><?= Html::encode($this->title) ?></title>
<?php $this->head() ?>
</head>
<body>
<?php $this->beginBody() ?>
<div class="wrap">
<?php
NavBar::begin([
'brandLabel' => 'GM Pharmaceuticals',
'brandUrl' => Yii::$app->homeUrl,
'options' => [
'class' => 'navbar-inverse navbar-fixed-top',
],
]);
$menuItems = [
['label' => 'Home', 'url' => ['/site/index']],
['label' => 'About', 'url' => ['/site/about']],
['label' => 'Contact', 'url' => ['/site/contact']],
];
if (Yii::$app->user->isGuest) {
$menuItems[] = ['label' => 'Signup', 'url' => ['/site/signup']];
$menuItems[] = ['label' => 'Login', 'url' => ['/site/login']];
} else {
$menuItems[] = [
'label' => 'Logout (' . Yii::$app->user->identity->username . ')',
'url' => ['/site/logout'],
'linkOptions' => ['data-method' => 'post']
];
}
echo Nav::widget([
'options' => ['class' => 'navbar-nav navbar-right'],
'items' => $menuItems,
]);
NavBar::end();
?>
<?php // echo $this->render('_search', ['model' => $searchModel]); ?>
<div class="container-fluid">
<?= Breadcrumbs::widget([
'links' => isset($this->params['breadcrumbs']) ? $this->params['breadcrumbs'] : [],
]) ?>
<?= Alert::widget() ?>
<div class="col-xs-4 col-sm-4 col-lg-2" style="padding-left: 0px;">
<?php
echo SideNav::widget([
'type' => SideNav::TYPE_DEFAULT,
'heading' => '<i class="glyphicon glyphicon-cog"></i> Menu',
'items' => [
[
'url' => Yii::$app->homeUrl,
'label' => 'Home',
'icon' => 'home',
],
[
'label' => 'Product',
'icon' => 'glyphicon glyphicon-baby-formula',
//'visible'=>Yii::$app->user->can('s_add-parties'),
'items' => [
[
'url' => 'http://localhost:8080/advanced/frontend/web/index.php?r=batchno/productbatch/create',
'label' => 'New Batch',
'icon' => 'glyphicon glyphicon-plus-sign',
'visible'=>Yii::$app->user->can('c_billing-person'),
],
[
'url' => 'http://localhost:8080/advanced/frontend/web/index.php?r=batchno/productbatch',
'label' => 'Edit Batch',
'icon' => 'glyphicon glyphicon-edit',
'visible'=>Yii::$app->user->can('c_billing-person'),
],
],
],
[
'label' => 'Party',
'icon' => 'glyphicon glyphicon-user',
//'visible'=>Yii::$app->user->can('s_add-parties'),
'items' => [
[
'url' => 'http://localhost:8080/advanced/frontend/web/index.php?r=Parties/parties',
'label' => 'New Party',
'icon' => 'glyphicon glyphicon-plus-sign',
'visible'=>Yii::$app->user->can('s_add-parties'),
],
],
],
[
'url' => 'http://localhost:8080/advanced/backend/web/index.php?r=tc/bills',
'label' => 'Transport',
'icon' => 'glyphicon glyphicon-send',
'visible'=>Yii::$app->user->can('c_billing-person'),
],
[
'label' => 'Payment',
'icon' => 'glyphicon glyphicon-piggy-bank',
'visible'=>Yii::$app->user->can('c_payment-collection'),
'items' => [
[
//'url' => 'http://localhost:8080/advanced/frontend/web/index.php?r=payment/payment',
'label' => 'Gopalbabu',
'icon' => 'glyphicon glyphicon-usd',
'visible'=>Yii::$app->user->can('s_create-payment'),
'items' =>[
[
'url' => 'http://localhost:8080/advanced/frontend/web/index.php?r=payment/payment/create',
'label' => 'New',
'icon' => 'glyphicon glyphicon-plus-sign',
'visible'=>Yii::$app->user->can('s_create-payment'),
],
[
'url' => 'http://localhost:8080/advanced/frontend/web/index.php?r=payment/payment',
'label' => 'View & Update',
'icon' => 'glyphicon glyphicon-edit',
'visible'=>Yii::$app->user->can('s_create-payment'),
],
],
],
[
//'url' => 'http://localhost:8080/advanced/frontend/web/index.php?r=sbp/payments',
'label' => 'Sanatbabu',
'icon' => 'glyphicon glyphicon-usd',
'visible'=>Yii::$app->user->can('s_create-payment'),
'items' =>[
[
'url' => 'http://localhost:8080/advanced/frontend/web/index.php?r=sbp%2Fpayments%2Fcreate',
'label' => 'New',
'icon' => 'glyphicon glyphicon-plus-sign',
'visible'=>Yii::$app->user->can('s_create-payment'),
],
[
'url' => 'http://localhost:8080/advanced/frontend/web/index.php?r=sbp/payments',
'label' => 'View & Update',
'icon' => 'glyphicon glyphicon-edit',
'visible'=>Yii::$app->user->can('s_create-payment'),
],
],
],
],
],
[
'label' => 'Help',
'icon' => 'question-sign',
'items' => [
['label' => 'About', 'icon'=>'info-sign', 'url'=>'#'],
['label' => 'Contact', 'icon'=>'phone', 'url'=>'#'],
],
],
],
]);
?>
</div>
<div class="col-xs-8 col-sm-8 col-lg-10" style="padding-left: 0px;">
<?= $content ?>
</div>
</div>
</div>
<footer class="footer">
<div class="container">
<p class="pull-left">© My Company <?= date('Y') ?></p>
<p class="pull-right"><?= Yii::powered() ?></p>
</div>
</footer>
<?php $this->endBody() ?>
</body>
</html>
<?php $this->endPage() ?>

I guess you have missed a <div>,
try <br> tag after main div in views/layout/main.php
or check one by one all divs starting and closing properly.

I found the solution. I changed <div class="container-fluid"> to <div class="container"> and it worked.

Related

Yii2 gridview buttons problem (possibly after pjax)

<?= GridView::widget([
'id' => 'CompanyGrid',
'dataProvider' => $dataProvider,
'filterModel' => $searchModel,
'floatHeader'=>true,
'floatOverflowContainer'=>true,
'floatHeaderOptions'=>['top'=>'0'],
'pjax'=>true,
'pjaxSettings' => [
'options' => [
'enablePushState' => false,
'enableReplaceState' => true,
]
],
'hover'=>true,
'toolbar' => [
'{export}',
'{toggleData}'
],
'panel' => [
'heading'=>'<h3 class="panel-title"><i class="glyphicon glyphicon-globe"></i> Companies</h3>',
'type'=>'secondary',
'before'=>Html::button('Create Company', ['value'=>Url::to('index.php?r=Company/company/create'), 'title' => 'Create Company', 'class' => 'btn btn-success', 'id' => 'modalButton']),
'after'=>false,
],
'columns' => [
['class' => 'kartik\grid\SerialColumn'],
'CompanyID',
'CompanyName',
['class' => 'kartik\grid\ActionColumn',
'template' => '{view} {update} {delete}',
'buttons' => [
'view' => function($url, $model){
return Html::a('<span class="fa fa-eye"></span>', ['view', 'id' => $model->CompanyID], [
'class' => 'activity-view-link',
'data-pjax'=>'w0',
'title' => Yii::t('yii', 'View Company: '.$model->CompanyID),
'data-toggle' => 'modal',
'data-target' => '#modal',
]);
},
'update' => function($url, $model){
return Html::a('<span class="fa fa-edit"></span>', ['update', 'id' => $model->CompanyID], [
'class' => 'activity-view-link',
'title' => Yii::t('yii', 'Edit Company: '.$model->CompanyID),
'data-toggle' => 'modal',
'data-target' => '#modal',
]);
},
'delete' => function($url, $model){
return Html::a('<span class="fa fa-trash"></span>', ['delete', 'id' => $model->CompanyID], [
'class' => '',
'data' => [
'confirm' => 'Are you absolutely sure? This action is not reversible',
'method' => 'post',
],
]);
}
],
],
],
]); ?>
In Controller
public function actionView($id)
{
$model = Company::findOne($id);
return $this->renderAjax('view', [
'model' => $model,
]);
}
I am new in yii2-advance-apps and i am trying to solve this problem. Already worked on this problem and cannot find any solution for this.
The problem is when I click on the gridview actions buttons, it works. However, after PJax, the button just don't work anymore.
However, if i reload the page, the button works again.
How to solve this problem. Thank you in advance.
'data-pjax' => 0, in action buttons options and not 'w0'

PJax() not working in yii2

I have two modules. The one won't create traffic using Pjax(). This one with exact same code for Grid will create traffic. Any ideas, why?
Here is exactly same Gridcode for both modules:
<?=
Html::endForm();
Pjax::begin();//this is ineffective! Why !!
?>
<div class="col-md-10">
<div class="box box-primary">
<?=
GridView::widget([
'dataProvider' => $dataProvider,
'filterModel' => $searchModel,
'filterSelector' => '.choiceRadio',
'id' => 'cb',
'columns' => $gridColumn,
'options' => [
'style' => 'overflow: auto; word-wrap: break-word;'
],
'pjax' => true,
'pjaxSettings' => [
'neverTimeout' => true,
],
'panel' => [
"heading" => "<h3 class='panel-title'><i class='glyphicon glyphicon-globe'></i> " . $this->title . "</h3>",
'type' => 'danger',
'after' => Html::a('<i class="glyphicon glyphicon-repeat"></i> Reset Grid', ['/mail/mail-eingang/index'], ['class' => 'btn btn-warning', 'title' => 'Setzt die GridView zurück']),
'toggleDataOptions' => ['minCount' => 10],
],
'toolbar' => [
'{export}',
'{toggleData}'
],
]);
Pjax::end();
?>
</div>
</div>
</div>

Yii2 How to save same file name but different file or content?

How to save same name but different content for example, samplename.docx. Now i want to save it again but the result the same. When i create a new report and use the name samplename it will overwrite the other same name. So in the uploads folder the samplename.docx is only one. But in the dgView is more than one.
This is my controller:
public function actionCreate()
{
$model = new reportDetails();
if ($model->load(Yii::$app->request->post()))
{
$project =$model->doc_name;
$model->upload_file= UploadedFile::getInstance($model,'doc_file');
$model->upload_file->saveAs('uploads/'.$project.'.'.$model->upload_file->extension);
$model->doc_file='uploads/'.$project.'.'.$model->upload_file->extension;
$model->doc_name=$project.'.'.$model->upload_file->extension;
$model->save();
Yii::$app->getSession()->setFlash('success','Data saved!');
return $this->redirect(['view','id'=> $model->report_id]);
}
else {
return $this ->render('create', [
'model'=>$model,
]);
}
}
This is my model:
public $upload_file;
public function rules()
{
return [
[['reference_no', 'subject', 'doc_for', 'doc_from', 'doc_date', 'doc_file', 'doc_name', 'drawer_id'], 'required'],
[['doc_date'], 'safe'],
[['drawer_id'], 'integer'],
[['reference_no', 'doc_for', 'doc_from'], 'string', 'max' => 200],
[['subject'], 'string', 'max' => 255],
[['doc_file', 'doc_name'], 'string', 'max' => 50],
[['user_id'],'string'],
];
}
/**
* #inheritdoc
*/
public function attributeLabels()
{
return [
'report_id' => 'Report ID',
'reference_no' => 'Reference No:',
'subject' => 'Subject:',
'doc_for' => 'For:',
'doc_from' => 'From:',
'doc_date' => 'Document Entry Date:',
'doc_file' => 'Document File:',
'doc_name' => 'Document Name:',
'drawer_id' => 'Drawer ID:',
'user_id' => 'Encoder Name:',
];
}
And this is my form:
<?php $form = ActiveForm::begin(['options' => ['enctype' => 'multipart/form-data']]); ?>
<?= Html::button('<i class="fa fa-plus"></i> Add Person', ['value' => Url::to('index.php?r=name/create'), 'class' => 'btn btn-custom-pos btn-success', 'id' => 'officialsfor']) ?>
</br>
</br>
<?php Pjax::begin(['id' => 'for_from']) ?>
<div class="col-sm-6">
<?= $form->field($model, 'doc_for')->widget(Select2::classname(), [
'data' => ArrayHelper::map(Name::find()->asArray()->all(),
'name_id',
function($model, $defaultValue){
return $model['position'].' '.$model['fname'].' '.$model['mname'].' '.$model['lname'];
}),
'language' => 'en',
'options' => ['placeholder' => 'Choose a person ...'],
'pluginOptions' => [
'allowClear' => true,
'width' => 500,
],
]); ?>
</div>
<div class="col-sm-6">
<?= $form->field($model, 'doc_from')->widget(Select2::classname(), [
'data' => ArrayHelper::map(Name::find()->asArray()->all(),
'name_id',
function($model, $defaultValue){
return $model['position'].' '.$model['fname'].' '.$model['mname'].' '.$model['lname'];
}),
'language' => 'en',
'options' => ['placeholder' => 'Choose a person ...'],
'pluginOptions' => [
'allowClear' => true,
'width' => 500,
],
]); ?>
<?php Pjax::end(); ?>
</div>
</br>
</br></br></br>
<div class="broder" style=" border-radius: 5px; padding: 12px; ">
</div>
<div class="col-sm-6">
<?= $form->field($model, 'user_id')->textInput(['type' => 'hidden','style'=>'width:500px;','placeholder' => 'Enter a Reference No....','value' =>ucfirst(Yii::$app->user->identity->first_name) . ' ' . ucfirst(Yii::$app->user->identity->middle_name) . ' ' . ucfirst(Yii::$app->user->identity->last_name)]) ?>
<?= Html::activeLabel($model, 'user_id', ['label'=>ucfirst(Yii::$app->user->identity->first_name) . ' ' . ucfirst(Yii::$app->user->identity->middle_name) . ' ' . ucfirst(Yii::$app->user->identity->last_name),'style' => 'font-size: 21px;','class' => 'color']) ?>
<br>
<br>
<?= $form->field($model, 'reference_no')->textInput(['style'=>'width:500px','placeholder' => 'Enter a Reference No....']) ?>
<?= $form->field($model, 'subject')->textInput(['maxlength'=>true,'style'=>'width:500px','placeholder' => 'Enter a Subject....']) ?>
<?= $form->field($model, 'doc_date')->widget(
DatePicker::className(), [
'inline' => false,
'options' => ['placeholder' => 'Choose a Entry Date ...'],
'clientOptions' => [
'autoclose' => true,
'format' => 'yyyy-mm-dd'
]
]);?>
</div>
<div class="col-sm-6" style="padding-top: 14px; ">
</br>
</br>
</br></br>
<?= $form->field($model, 'drawer_id')->textInput(['maxlength'=>true,'style'=>'width:500px','placeholder' => 'Enter a Drawer ID....', ]) ?>
<?= $form->field($model, 'doc_name')->textInput(['maxlength'=>true,'style'=>'width:500px','placeholder' => 'Enter a Document Name....']) ?>
<?= $form->field($model, 'doc_file')-> widget(
FileInput::classname(),[
'name' => 'doc_file',
'options' => ['accept' => '.docx','.doc','.docs'],
'pluginOptions' => [
'showPreview' => false,
'showCaption' => true,
'showRemove' => true,
'showUpload' => false
]
]);
?>
use
if(file_exists('...')){
// upload file with , new file name
}
else{
// upload file
}
Try this one
if (file_exists($fileFullPath)) {
unlink ($fileFullPath);
echo "delete existing file creating new <br />";
}else{
echo "file not exists creating new <br />";
}

Font Awesome use inside the Yii2 SideNavbar

I have followed the guidelines given by GitHub Yii2 fontawesome and successfully installed via composer. My problem is the code they given to get the specific icon to my SideNavbar is not working for me.
I have used FA::icon('home') inside my SideNav menu but this code out put only "> this. not the home icon.
code which i was used in my sidenav menu.
<?= SideNav::widget([
'type' => SideNav::TYPE_DEFAULT,
'heading' => 'System Functions',
'items' => [
[
'url' => '../dashboard/manager',
'label' => Yii::t('app','Dashboard'),
'icon' => 'home',
'active' => ($currentpage == 'Manager')
],
[
'url' => '#',
'label' => 'Purchase',
'icon' => FA::icon('home'),
'items' => [
[
'url' => '../dashboard/suppliers',
'label' => Yii::t('app','Suppliers'),
'icon'=>'transport',
'active' => ($currentpage == 'Suppliers')
],
[
'url' => '../dashboard/leaf-entry',
'label' => 'Leaf Collection',
'icon'=>'leaf',
'active' => ($currentpage == 'Leaf')
],
[
'url' => '../dashboard/payments',
'label' => 'Payments',
'icon'=>'phone',
'active'=> ($currentpage == 'Payments')
],
['label' => 'Reports', 'icon'=>'phone', 'url'=>'#']
],
],
[
'label' => 'Stock',
'icon' => 'question-sign',
'items' => [
['label' => 'Live Stock', 'icon'=>'info-sign', 'url'=>'#'],
['label' => 'Auction Despatch', 'icon'=>'phone', 'url'=>'#'],
['label' => 'Production Tracker', 'icon'=>'phone', 'url'=>'#'],
['label' => 'Reports', 'icon'=>'phone', 'url'=>'#']
],
],
[
'label' => 'Human Resource',
'icon' => 'question-sign',
'items' => [
['label' => 'Employees', 'icon'=>'info-sign', 'url'=>'#'],
['label' => 'Time Tracker', 'icon'=>'phone', 'url'=>'#'],
['label' => 'Payments', 'icon'=>'phone', 'url'=>'#'],
['label' => 'Reports', 'icon'=>'phone', 'url'=>'#']
],
],
[
'label' => 'End of day calculations',
'icon' => 'question-sign',
'items' => [
['label' => 'Water Basis', 'icon'=>'info-sign', 'url'=>'#'],
['label' => 'Dry Basis', 'icon'=>'phone', 'url'=>'#'],
['label' => 'Out Turn', 'icon'=>'phone', 'url'=>'#'],
['label' => 'Refuced Tea', 'icon'=>'phone', 'url'=>'#']
],
],
],
]);
?>
Output
And I also have used the Chrome DevTools to inspect the element, which gives me the below result. Hope this would be the problem.
You are using SideNav::widget, which uses the default icon prefix as "glyphicon glyphicon-". This is a SideNav property. If you are creating a SideNav using a glyphicon icon, then it will only use glyphicon icons. If you want to use Font Awesome icons, you need to change the icon prefix like this:
echo SideNav::widget([
'type' => SideNav::TYPE_DEFAULT,
'heading' => 'System Functions',
'iconPrefix' => ' ',
'items' => [
[
'url' => '#',
'label' => 'Home',
'icon' => 'fa fa-home',
]
]
]);
You can use only one type of icons at a time.

Yii2 Link FrontEnd To BackEnd

How to link from frontend page to backend in Yii2 using advanced template.... I want to link the login button from frondend to backend...when I click on login button in frontend it can redirect to login page in backend that I already created...
<div class="wrap">
<?php
NavBar::begin([
'brandLabel' => 'My Company',
'brandUrl' => Yii::$app->homeUrl,
'options' => [
'class' => 'navbar-inverse navbar-fixed-top',
],
]);
$menuItems = [
['label' => 'Home', 'url' => ['/site/index']],
['label' => 'About', 'url' => ['/site/about']],
['label' => 'Contact', 'url' => ['/site/contact']],
];
if (Yii::$app->user->isGuest) {
$menuItems[] = ['label' => 'Signup', 'url' => ['/site/signup']];
$menuItems[] = ['label' => 'Login', 'url' => ['/site/login']];
} else {
$menuItems[] = [
'label' => 'Logout (' . Yii::$app->user->identity->username . ')',
'url' => ['/site/logout'],
'linkOptions' => ['data-method' => 'post']
];
}
echo Nav::widget([
'options' => ['class' => 'navbar-nav navbar-right'],
'items' => $menuItems,
]);
NavBar::end();
?>
<div class="container">
<?= Breadcrumbs::widget([
'links' => isset($this->params['breadcrumbs']) ? $this->params['breadcrumbs'] : [],
]) ?>
<?= Alert::widget() ?>
<?= $content ?>
</div>
</div>
`
You can try a relative path
if (Yii::$app->user->isGuest) {
$menuItems[] = ['label' => 'Signup', 'url' => ['/site/signup']];
$menuItems[] = ['label' =>'Login','url' =>'../../../backend/site/login'];
} else {
add this in common/config/main.php
under the section components
'components' => [
.....
'urlManager' => [
'class' => 'yii\web\UrlManager',
'enablePrettyUrl' => false,
'showScriptName' => true,
],
.......
add to section components after urlManager in frontend/config/main.php
'urlManagerBackend' => [
'class' => 'yii\web\UrlManager',
'baseUrl' => 'http://backend.site.local',
'hostInfo' => 'http://backend.site.local',
'enablePrettyUrl' => true,
'enableStrictParsing' => true,
'showScriptName' => false,
],
in frontend/views/layout
add something like this
$menuItems = [
['label' => 'Home', 'url' => ['/site/index']],
['label' => 'Admin panel', 'url' => Yii::$app->urlManagerBackend->createUrl([''])],
];