I
I
Iossarian2019-04-01 16:20:14
Yii
Iossarian, 2019-04-01 16:20:14

How to trim attribute length for a slug?

Good afternoon. You need to cut off the title of the article and give the resulting line for saving for slugs. I act as follows:

public $strTitle;

public function getSlug () {
        $this->strTitle = mb_substr($this->title, 0, 59);
        return $this->strTitle;
    }

public function behaviors()
{
    return [
        [
            'class' => SluggableBehavior::className(),
            'attribute' => 'strTitle',
            'slugAttribute' => 'slug',
        ],
    ];
}

but of course it doesn't work properly. The essence of the problem is simple, but I don’t understand how to implement it in yii.

Answer the question

In order to leave comments, you need to log in

4 answer(s)
D
Dmitry, 2019-04-01
@slo_nik

In the model, set the "value" property

public function behaviors()
{
    return [
        [
            'class' => SluggableBehavior::class,
            //'attribute' => 'title',
            'value' => function($event){
               return mb_substr($this->title, 0, 5);
            }
        ]
    ];
}

Returns a five character slug from "Test slugbehaviors".

Алексей Скляров, 2017-01-16
@0example

Создаем файл mobile.css , пишем в него код:

@media only screen and (min-width: 600px) and (max-width: 1023px) {
 body {color:#fff}
 header {background-color:red;}
}

То есть для ширины от 600 пкс до 1023 пкс будет выполняться body {color:#fff} и header {background-color:red;}

M
Mr. Pavlyukov, 2017-01-16
@pavlyukov_i

Вот на оф.сайте информация - клик
А вообще бы Вы сначала до ума довели desktop версию. Горизонтальный скрол, поехавшие блоки. Фиксите.

M
Maxim Timofeev, 2017-01-16
@webinar Куратор тега Веб-разработка

Bootstrap has responsiveness out of the box and is implemented through grid:
getbootstrap.com/css/#grid-media-queries
What's the problem?
Here you have types of cakes in your code, they have class="col-md-3" and why not do class="col-xs-12 col-sm-6 col-md-3" - it will be adaptive, including same spirit with the rest.
Well, the header is the same or without bootstrap using media queries.
If you want rubber, try to minimize fixed values ​​like px, and use % or vh,vw,rem and other relative units. A case in point is your logo. It looks terrible on small displays.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question