How can I control row height and cell padding in yii2 detailView? - html

I want to decrease the size of a detail view. I was able to decrease font-size through css, but can not decrease row size or padding of the generated table.
<div class="col-md-3">
<?= DetailView::widget([
'model' => $model,
'attributes' => [
'id',
'jmn',
'pri',
'rci',
'adr',
'tel',
'eml',
],
]) ?>
</div>
css
.detail-view {
font-size: 10px; -> this works
}
td {
padding: 0px; -> this doesnt do anything
margin: 0px; -> this doesnt do anything
background:green; -> this works (a test :-)
}
tr { line-height: 30px; } -> this doesnt do anything

Add style in the interessed field e.g.
<div class="col-md-3">
<?= DetailView::widget([
'model' => $model,
'attributes' => [
'id',
'jmn',
....
[
'attribute' => 'attribute_name',
....
'options' => ['style' => 'width:90px;'],
.....
],
....
]) ?>
</div>

First, try to put !important at the end of last css line:
td { padding:0px !important; height: 5px !important; }
Also it's better to be more specific in css selector. So something like this is better:
#your-table-id tr { line-height: 30px !important; }
If did not work, try to add css style inside the widget in this way:
<?= DetailView::widget([
'model' => $model,
'attributes' => [
[
'label' => 'ID',
'value' => $model->id,
'options' => ['style' => ' line-height: 30px']
],
...
],
]) ?>

Related

SVG pictures are not displayed

I am using images in svg format for the first time. and they aren't displayed my project. I tried with png and it works. I also tried changing the size, color etc.. Thank you!
Data file where the images and their title are stored (
I don't think that's the problem because when I replace the links with .jpg pictures, it works)
<?php
namespace App;
class Data{
public static function getSkills()
{
return [
// array data
array("name" => "HTML5", "icon" => '/home/student/Bureau/Portfolio/public/images/skills/bootstrap.svg'),
array("name" => "CSS3", "icon" => 'public/images/skills/css.svg' ),
array("name" => "Sass", "icon" => 'public/images/skills/html5.svg'),
array("name" => "Bootstrap", "icon" => 'public/images/skills/html5.svg'),
array("name" => "JavaScript", "icon" => 'public/images/skills/html5.svg'),
array("name" => "MySQL", "icon" => 'public/images/skills/html5.svg'),
array("name" => "PHP", "icon" => 'public/images/skills/html5.svg'),
array("name" => "React JS", "icon" => 'public/images/skills/html5.svg'),
array("name" => "Redux", "icon" => 'public/images/skills/html5.svg'),
array("name" => "GitHub", "icon" => 'public/images/skills/html5.svg'),
array("name" => "Trello", "icon" => 'public/images/skills/html5.svg'),
array("name" => "VSCode", "icon" => 'public/images/skills/html5.svg'),
array("name" => "Linux Ubuntu", "icon" => 'public/images/skills/html5.svg'),
];
}
}
Controller
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use App\Data;
class SkillsController extends Controller
{
public function index()
{
return view('competences', [
'competences' => Data::getSkills()
]);
}
}
competences.blade.php
#include('layouts/navbar')
<div class="skills">
<h1 class="skills-title text-center"> <span class="the-span "> Compétences </span></h1>
<h2 class="subtitle text-center"> <span class="the-span "> •Les langages, outils et frameworks que j’utilise </span></h2>
<ul class="skills-list text-center m-auto">
#foreach ($competences as $competence)
<li class="skills-list-skill" key="{{$competence['icon']}}">
<embedy src="{{$competence['icon']}}" alt="" class="skills-list-skill-icon" />
<p class="skills-list-skill-title">{{$competence['name']}}</p>
</li>
#endforeach
</ul>
</div>
#include ('layouts/footer')
Scss file
// Variables
#import 'variables';
.skills {
margin-bottom: 10em;
margin: 3em 0 2em 1em;
&-list {
display: flex;
flex-wrap: wrap;
#media screen and (min-width: 1440px) {
width: 60%;
}
#media screen and (min-width: 1024px) {
width: 70%;
}
&-skill {
width: 7em;
#media screen and (max-width: 320px) {
width: 5em;
}
background-color: $second-font-color;
margin: 3em 3em 1em 0;
min-height: 7em;
display: flex;
flex-wrap: wrap;
justify-content: center;
padding: 1em;
border-radius: .5em;
font-size: .8em;
text-align: center;
&:nth-child(odd) {
img {
color: $font-color;
}
}
&:nth-child(even) {
img {
color: $second-font-color;
}
}
&:hover {
transition: .8s;
box-shadow: 0px 0px 20px 2px rgba(255, 255, 255, 0.4);
}
&-icon {
padding: 1em 2em;
width: 40px;
height: 40px;
color : white;
}
}
}
}
I don't know what is <embedy> tag for, you can simply try load your svg icon with img tag
<img src="{{$competence['icon']}}" alt="" class="skills-list-skill-icon" />
also you dont need to add complete address to getaddress method ,you can just add icon name and in code load with asset
<img src="{{asset('/images/skills/'.$competence['icon'].')}}" alt="" class="skills-list-skill-icon" />

why the controller don't read an if function loading the parameters?

this is my create function in my controller:
public function actionCreate()
{
$searchModel = new AutoriSearch();
$model = new Autori();
$model->RIDUtente = Yii::$app->user->getId();
$model->Accettazione='SI';
$dataProvider = $searchModel->search(Yii::$app->request->queryParams);
if ($model->load(Yii::$app->request->post()) ) {
$model->modified = date( 'y-m-d' );
$model->creator_aut = Yii::$app->user->getId();
$model->Utenteup_autori = Yii::$app->user->getId();
if ($model->IParte) {
$model->CampoRicerca = $model->IParte." ".$model->IIParte." ".$model->Prefisso." ".$model->Qualificazione." ".$model->IIEnte." ".$model->Sigla;
}
if($model->Accettazione == "" || $model->Accettazione == 'SI' ){
$model->RIDAutore = $model->IDAutore;
}
$model->save();
return $this->redirect(['view', 'id' => $model->IDAutore]);
}
return $this->render('create', [
'model' => $model,
'dataProvider' => $dataProvider,
'searchModel' => $searchModel,
]);
}
The problem is that the record is not saved, and the system don't enter in the if function "if ($model->load(Yii::$app->request->post()) )". So this is a problem. In others controller it gives me no error, for this controller it gives me the error. This is strange. Can anyone help me fast please? It's very important!!!! Thank you.
This is the form:
<div class="autori-form">
<?php $form = ActiveForm::begin([
'action' => ['index'],
'method' => 'get',
'type' => ActiveForm::TYPE_HORIZONTAL,
]); ?>
<?= $form->field($model, 'IParte', ['labelOptions'=>['style'=>'font-size: 12px;']])->textInput(['maxlength' => true, 'style'=>'width:190px; height: 30px;'])->label('I Parte del nome') ?>
<?= $form->field($model, 'IIParte', ['labelOptions'=>['style'=>'position: relative; top: -63px; left: 360px;font-size: 12px;']])->textInput(['maxlength' => true, 'style'=>' height: 30px; width:190px; position: relative; position: relative; top: -58px; left: 360px;'])->label('Autori:<br>II Parte del nome') ?>
<?= $form->field($model, 'IIEnte', ['labelOptions'=>['style'=>'width: 100px; position: relative; top: -120px; left: 800px;font-size: 12px;']])->textInput(['maxlength' => true, 'style'=>' height: 30px; width:190px; position: relative; top: -116px; left: 800px;'])->label('Enti: Ente subordinato') ?>
<div style="position: relative; top: -120px;">
<?= $form->field($model, 'Prefisso', ['labelOptions'=>['style'=>'font-size: 12px;']])->textInput(['maxlength' => true, 'style'=>' height: 30px; width:300px'])->label('Appellativi o altra parte del nome') ?>
<?= $form->field($model, 'Sigla', ['labelOptions'=>['style'=>'font-size: 12px;']])->textInput(['maxlength' => true, 'style'=>' height: 30px; width:300px'])->label('Sigla dell\'ordine') ?>
<?= $form->field($model, 'Qualificazione', ['labelOptions'=>['style'=>'font-size: 12px;']])->textInput(['maxlength' => true, 'style'=>' height: 30px; width:300px'])->label('Qualificazioni') ?>
<?= $form->field($model, 'Fonte', ['labelOptions'=>['style'=>'font-size: 12px;']])->textInput(['maxlength' => true, 'style'=>' height: 30px; width:300px']) ?>
<?= $form->field($model, 'RIDTipoAutore', ['labelOptions'=>['style'=>'font-size: 12px;']])->dropdownList(
TipiAutore::find()
->select(['TipoAutore'])
->indexBy('IDTipoAutore')
->column(),
['prompt'=>'', 'style'=>' height: 30px; width:300px']
)->label('Tipo Autore') ?>
<?= $form->field($model, 'Accettazione', ['labelOptions'=>['style'=>'font-size: 12px;']])->dropdownList(
Autori::find()
->select(['Accettazione'])
->indexBy('Accettazione')
->column(),
['style'=>' height: 30px; width:300px', 'onchange' => 'accettato(this)']
)->label('Accettazione') ?>
<?php //$form->field($model, 'CampoRicerca')->textInput(['maxlength' => true]) ?>
<?= $form->field($model, 'RIDUtente')->hiddenInput(['value'=> Yii::$app->user->identity->id])->label(false) ?>
<?= $form->field($model, 'RIDAutore', ['labelOptions'=>['style'=>'font-size: 12px; position: relative; top: -28px;']])->textInput(['maxlength' => true, 'style'=>' height: 30px; width:300px; position: relative; top: -28px;', 'disabled' => true])->label('Forma accettata') ?>
</div>
<a name="button" id="btnMostra" style="position: relative; top: -199px; left: 540px; cursor: pointer;">Clicca per ricercare la forma accettata</a>
<script>
function accettato(select) {
console.log(select,$(select));
$("#autori-ridautore").prop("disabled", $(select).val()!="NO");
}
</script>
<?= Html::hiddenInput( 'modified', strtotime("now") ); ?>
<div class="form-group" style="position: relative; top: -170px; left: 860px; width: 200px;">
<?= Html::submitButton(Yii::t('app', 'Salva'), ['class' => 'btn btn-success']) ?>
<?= Html::a('Annulla', ['autori/index'], ['class'=>'btn btn-info']) ?>
</div>
<?php ActiveForm::end(); ?>
</div>
RULES OF Autori.php:
public function rules()
{
return [
[['RIDUtente', 'modified', 'RIDTipoAutore'], 'required'],
[['RIDUtente', 'RIDAutore', 'RIDTipoAutore', 'creator_aut'], 'integer'],
[['IParte', 'IIEnte'], 'string', 'max' => 100],
[['IIParte', 'Qualificazione'], 'string', 'max' => 50],
[['Prefisso'], 'string', 'max' => 30],
[['Sigla'], 'string', 'max' => 10],
[['Accettazione'], 'string', 'max' => 2],
[['CampoRicerca'], 'string', 'max' => 400],
[['Fonte'], 'string', 'max' => 3200],
[['modified'], 'string', 'max' => 8],
];
}
RULES OF AutoriSearch Model:
public function rules()
{
return [
[['IDAutore', 'RIDUtente', 'RIDAutore', 'RIDTipoAutore', 'creator_aut'], 'integer'],
[['autoreMix', 'IParte', 'IIParte', 'Prefisso', 'Qualificazione',
'IIEnte', 'Sigla', 'Accettazione', 'CampoRicerca',
'Fonte', 'modified'], 'safe'],
];
}
your forms method is get but you are getting data by post and this is incompatible
'method' => 'get',
$model->load(Yii::$app->request->post()

Yii2 doesn't work yii2-poll-widget

I use yii2-poll-widget on my page.
I installed it:
php composer.phar require "pollext/poll":"dev-master"
And write on my page:
<?php
use pollext\poll\Poll;?>
<?php
echo Poll::widget([
'pollName'=>'Do you like PHP?',
'answerOptions'=>
[
'Yes',
'No',
],
]);
?>
But I get error:
Unknown Property – yii\base\UnknownPropertyException
Setting unknown property: pollext\poll\Poll::pollStatus
How can I solve my problem?
I do not recommend pollext/poll because it contains multiple errors in its core code, like missing ) or undefined index. We (I and 2 more people) tried to fix errors in its core files by hand (I know we shouldn't do that as it's a widget, sitting in vendor directory but at least we could see if it works at all).
You can try to use this code below (what we added/modified is not much, we did more to improve design and functionality but still wasn't good enough, not worth to continue):
<?php
use yii\helpers\Html;
use yii\widgets\ActiveForm;
use pollext\poll\AjaxSubmitButton;
use yii\helpers\Url;
?>
<style>
.poll{
display: inline-block;
margin-top: 10px;
margin-bottom: 10px;
background: #ffffff;
}
.poll label{
width: 100%;
font-size: 10pt;
font-weight: bold;
display: block;
color: #464646;
}
.poll label:hover{
cursor: pointer;
}
.poll button[type="submit"]{
font-weight: bold;
font-size: 10pt;
margin-top: 10px;
color: #4682B4;
}
.poll-option-name{
font-weight: bold;
font-size: 10pt;
color: #464646;
}
.per_container{
font-weight: bold;
font-size: 10pt;
color: #464646;
padding: 0;
margin: 0;
max-width: 50px;
}
.support_forms button[type="submit"]{
border: none;
font-weight: normal;
color: #4682B4;
margin-left: 0;
padding: 0;
background: #ffffff;
}
.support_forms button[type="submit"]:hover{
text-decoration: underline;
}
.support_forms button[type="submit"]:focus{
outline: none;
border: none;
}
.support_forms{
margin-top: 0;
}
</style>
<div class="poll" style="width:<?php echo $params['maxLineWidth']+55;?>px;" >
<?php echo "<div style=\"max-width:".$params['maxLineWidth']."px; word-wrap: break-word; margin-bottom: 10px; font-size:12pt; font-weight:bold;\">".$pollData['poll_name']."</div>";?>
<?php $pullName = (isset($_POST['nameOfPoll'])) ? $_POST['nameOfPoll'] : '';?>
<?php if((Yii::$app->user->getId()==null && $_POST['pollStatus']!='show' && $isVote == false ) || ($pullName==$pollData['poll_name'] && $_POST['pollStatus']=='vote'&& $_POST['pollStatus']!='show' && Yii::$app->user->getId()==null)){
echo "Sign in to vote";
}?>
<?php if(($isVote == false && Yii::$app->user->getId()!=null && !empty($_POST['pollStatus']) && $_POST['pollStatus'] !='show') || ($pullName==$pollData['poll_name'] && $_POST['pollStatus']=='vote'&& $_POST['pollStatus']!='show' && Yii::$app->user->getId()!=null)){?>
<?php echo Html::beginForm('#', 'post', ['class'=>'uk-width-medium-1-1 uk-form uk-form-horizontal']); ?>
<?php echo Html::activeRadioList($model,'voice',$answers); ?>
<input type="hidden" name="poll_name" value="<?=$pollData['poll_name']?>"/>
<?php AjaxSubmitButton::begin([
'label' => 'Vote',
'ajaxOptions' => [
'type'=>'POST',
'url'=>'#',
'success' => new \yii\web\JsExpression('function(data){
$("body").html(data);
}'),
],
'options' => ['class' => 'customclass', 'type' => 'submit'],
]);
AjaxSubmitButton::end();
?>
<?php echo Html::endForm();
}
?>
<?php if (($isVote == false && !empty($_POST['pollStatus']) && $_POST['pollStatus'] !='show') || (Yii::$app->user->getId()==null && $_POST['pollStatus']!='show') || ($pullName==$pollData['poll_name'] && $_POST['pollStatus']=='vote'&& $_POST['pollStatus']!='show')){?>
<form method="POST" action="" class="support_forms">
<input type="hidden" name="nameOfPoll" value="<?=$pollData['poll_name']?>"/>
<input type="hidden" name="pollStatus" value="show"/>
<?php AjaxSubmitButton::begin([
'label' => 'Show results',
'ajaxOptions' => [
'type'=>'POST',
'url'=>'#',
'success' => new \yii\web\JsExpression('function(data){
$("body").html(data);
}'),
],
'options' => ['class' => 'customclass', 'type' => 'submit'],
]);
AjaxSubmitButton::end();
?>
</form>
<?php }?>
<?php if($isVote == true || ($pullName==$pollData['poll_name'] && $_POST['pollStatus']=='show') ){?>
<?php
for($i = 0; $i<count($answersData); $i++){
$voicesPer = 0;
if($sumOfVoices ==0){
$voicesPer = 0;
}else{
$voicesPer = round($answersData[$i]['value']/$sumOfVoices, 4);
}
$lineWidth = $params['maxLineWidth']*$voicesPer;
?>
<div class="single-line" style="margin-bottom: 10px; ">
<?php echo "<div class=\"poll-option-name\">".$answersData[$i]['answers'].": ".$answersData[$i]['value']."</div>"; ?>
<div style="width: <?php echo $params['maxLineWidth']; ?>px; height: <?php echo $params['linesHeight']; ?>px; background-color: <?php echo $params['backgroundLinesColor']; ?>; ">
<div style="width: <?php echo $lineWidth;?>px; height: <?php echo $params['linesHeight'] ?>px; background-color: <?php echo $params['linesColor']; ?>;">
<div class="per_container" style="display: block; line-height:<?php echo $params['linesHeight'] ?>px; height: <?php echo $params['linesHeight'] ?>px;
position: relative; left:<?php echo $params['maxLineWidth']+5; ?>px; margin: 0;"><?php echo ($voicesPer*100)."%"?></div>
</div>
</div>
</div>
<?php }?>
<?php }?>
<?php if ($isVote == false && !empty($_POST['pollStatus']) && $_POST['pollStatus'] == 'show'){?>
<form method="POST" action="" class="support_forms" style="margin-top: -10px;">
<input type="hidden" name="nameOfPoll" value="<?=$pollData['poll_name']?>"/>
<input type="hidden" name="pollStatus" value="vote"/>
<?php AjaxSubmitButton::begin([
'label' => 'Vote',
'ajaxOptions' => [
'type'=>'POST',
'url'=>'#',
'success' => new \yii\web\JsExpression('function(data){
$("body").html(data);
}'),
],
'options' => ['class' => 'customclass', 'type' => 'submit'],
]);
AjaxSubmitButton::end();
?>
<?php }?>
</form>
</div>
This modified come is taken from pollext/views/index.php file. In case you're wondering how it looks like:
Upper is a view for a person who didn't vote yet and below is a view for a person who have already voted.

CGridView change column width for raw type cell

I am using CGridView with 'raw' cell type. The cell contains text field generated using CHtml::textField. Here I cannot change the width of the column using headerHtmlOptions or htmlOptions. Please help.
$this->widget('zii.widgets.grid.CGridView', array(
'id'=>'mbook-grid',
'itemsCssClass'=>'table table-bordered table-condensed table-hover table-striped dataTable',
'dataProvider'=>$model->search(),
'afterAjaxUpdate'=>'calcquantity',
'enablePagination' => true,
'pagerCssClass'=>'dataTables_paginate paging_bootstrap table-pagination',
'pager' => array('header'=>'','htmlOptions'=>array('class'=>'pagination')),
'columns' => array(
array(
'class' => 'CCheckBoxColumn',
'id'=>'project_estimate_id',
'htmlOptions'=>array('style' => 'display:none'),
'headerHtmlOptions'=>array('style' => 'display:none'),
'selectableRows'=>2,
'value'=>'$data["project_estimate_id"]',
'checked'=>'true',
),
array('name'=>'description','value'=>'CHtml::textField("ProjectMBookGrid[description_".$data["project_estimate_id"]."]",$data["description"],array("class"=>"gridfield"))','type'=>'raw','header'=>'Description','headerHtmlOptions'=>array('style'=>'width: 5%;')),
array('name'=>'length','value'=>'CHtml::textField("ProjectMBookGrid[length_".$data["project_estimate_id"]."]",$data["length"],array("class"=>"gridfield","style"=>"text-align: right"))','type'=>'raw','header'=>'Length','headerHtmlOptions'=>array('style'=>'width:5%')),
array('name'=>'breadth','value'=>'CHtml::textField("ProjectMBookGrid[breadth_".$data["project_estimate_id"]."]",$data["breadth"],array("class"=>"gridfield","style"=>"text-align: right"))','type'=>'raw','header'=>'Breadth','htmlOptions'=>array('style'=>'text-align: right')),
array('name'=>'quantity','value'=>'CHtml::textField("ProjectMBookGrid[quantity_".$data["project_estimate_id"]."]",$data["quantity"],array("class"=>"gridfield","style"=>"text-align: right"))','type'=>'raw','header'=>'Quantity','htmlOptions'=>array('style'=>'text-align: right')),
),
'htmlOptions'=>array('class'=>'grid-view table-responsive hide-x-scroll'),
))
Below is the CSS
.table.dataTable {
clear: both;
margin-bottom: 10px;
}
.table-bordered.dataTable {
border-top: 1px solid #ddd;
}
table {
background-color: transparent;
max-width: 100%;
}
table {
border-collapse: collapse;
border-spacing: 0;
}
.hide-x-scroll {
overflow-x: scroll;
}
.grid-view {
padding: 15px 0;
}
I added
"style"=>"width:100%"
in CHtml::textField htmlOptions and was able to change the width of column

Twitter bootstrap Navbar justified links with logo/brand

I cant seem to justify my links and have my logo in the navbar. My links and logo will overlap on the left hand side. I want to make it so my links will justify to the right of my logo.
%body
%nav.navbar.navbar-inverse.navbar-fixed-top
.container-fluid
.navbar-header
%button.navbar-toggle.collapsed{"aria-controls" => "navbar", "aria-expanded" => "false", "data-target" => "#navbar", "data-toggle" => "collapse", :type => "button"}
%span.sr-only Toggle navigation
%span.icon-bar
%span.icon-bar
%span.icon-bar
.container-fluid
.navbar-header
%a.navbar-brand{:href => "#"}
%img{:alt => "IMage", :height => "50", :src => "/assets/logo.png"}
%ul.nav.navbar-nav.nav-justified
%li
%a{:href => "#"} link
%li
%a{:href => "#"} Link
%li
%a{:href => "#"} link
%li
%a{:href => "#"} link
%li
%a{:href => "#"} link
%li
%a{:href => "#"} link
%li
%a{:href => "#"} link
%li
%a{:href => "#"} link
css
.navbar {
position: relative;
background-color: #004170;
padding-top: 15px;
padding-bottom: 15px;
margin-bottom: 0;
font-size: 18px;
}
.navbar-nav.nav-justified > li{
float:none;
}
Try remove .navbar-nav class from navbar code.
%ul.nav.navbar-nav.nav-justified
to
%ul.nav.nav-justified
If your navigation slightly move down then you can set below properties :
.nav-justified {
width: 98%;
}
.nav-justified > li {
float: none;
}
It works for me.