You need to create a short blog post content, with a button for a possible transition to a separate page with full content. At the moment there is such code:

<?php use yii\helpers\Html; use yii\widgets\LinkPager; ?> <h1>Posts</h1> <ul> <?php foreach ($articles as $article): ?> <div> <div class="Artic_title"><h3><?= Html::encode("{$article->title},") ?>:<h3><p class="Artic_date"><?= $article->date_add ?></p><div> <p class="Artic_mess"><?= $article->message ?></p> </div> <?php endforeach; ?> </ul> <?= LinkPager::widget(['pagination' => $pagination]) ?> 

    1 answer 1

    If the question is how to cut the text, the function substr will help you, you can make a getter in the model and display a short text:

     SomeModel extends ActiveRecord { ... public function getShortMessage($length=100, $ellipses = true, $strip_html = true){ //удаляем теги если необходимо if ($strip_html) { $str = strip_tags($str); } if(strlen($str) <= $length) return $str; $shortStr = trim(substr($this->message, 0 , $length - 3)); //добавляем точки if ($ellipses) { $shortStr = trim($shortStr).'...'; } return $shortStr; } ... } 

    Then simply call this function.

     echo $article->getShortMessage() 

    If you have many such blocks, I advise you to process the text while saving, and save it in a separate field of the table.

    If you are only interested in the mysql query, you can use the LEFT function.

     SELECT LEFT(message, 200) AS short_message FROM table(s) WHERE ... 

    Remember to add a short_message field to the model.