truncateWords() публичный статический Метод

Truncates a string to the number of words specified.
public static truncateWords ( string $string, integer $count, string $suffix = '...', boolean $asHtml = false ) : string
$string string The string to truncate.
$count integer How many words from original string to include into truncated string.
$suffix string String to append to the end of truncated string.
$asHtml boolean Whether to treat the string being truncated as HTML and preserve proper HTML tags. This parameter is available since version 2.0.1.
Результат string the truncated string.
            <?php 
foreach ($nodes as $node) {
    ?>
                <div class="col-lg-3 col-md-3 col-xs-12 col-sm-3">
                    <div class="blog_inner">
                        <div class="blog-img blog-l">
                            <?php 
    echo \yii\helpers\Html::a(Yii::$app->imageCache->thumb($node->image, '600x400', ['class' => 'img-responsive']), ['review/view', 'slug' => $node->slug]);
    ?>
                        </div>
                        <h2><?php 
    echo \yii\helpers\Html::a($node->title, ['review/view', 'slug' => $node->slug], ['class' => 'info']);
    ?>
</h2>

                        <div class="post-date"><i class="fa fa-calendar"></i> <?php 
    echo date('d-m-Y', $node->updated_at);
    ?>
</div>
                        <p><?php 
    echo \yii\helpers\BaseStringHelper::truncateWords(strip_tags($node->content), 25);
    ?>
</p>
                    </div>
                </div>
            <?php 
}
?>
        </div>
    </div>
</section>
Пример #2
0
 * Панель управления книгами.
 */
use yii\helpers\Html;
$this->title = 'CRUD Author';
?>

<h1>Управление авторами</h1>

<p>
    <a class="btn btn-primary" href="<?php 
echo yii\helpers\Url::to(['back-author/create']);
?>
">Добавить</a>
</p>

<hr>

<?php 
echo yii\grid\GridView::widget(['dataProvider' => $dataProvider, 'filterModel' => $modelAuthor, 'columns' => ['id', 'name', ['attribute' => 'description', 'value' => function ($modelAuthor) {
    /** @var app\models\Author $modelAuthor */
    return \yii\helpers\BaseStringHelper::truncateWords($modelAuthor->description, 10);
}], ['attribute' => 'photo', 'format' => 'html', 'value' => function ($modelAuthor) {
    /** @var app\models\Author $modelAuthor */
    return $modelAuthor->photo ? Html::img($modelAuthor->photo) : '';
}], ['format' => 'html', 'label' => 'Опции', 'value' => function ($modelAuthor) {
    /** @var app\models\Author $modelAuthor */
    return Html::a('Просмотреть', ['back-author/view', 'id' => $modelAuthor->id], ['class' => 'btn btn-default']) . ' ' . Html::a('Изменить', ['back-author/update', 'id' => $modelAuthor->id], ['class' => 'btn btn-default']) . ' ' . Html::a('Удалить', ['back-author/delete', 'id' => $modelAuthor->id], ['class' => 'btn btn-danger']);
}]]]);
?>

Пример #3
0
echo $category_title;
?>
</h1>

<?php 
foreach ($nodes as $node) {
    ?>
<div class="col-lg-25 partner-item">
<?php 
    echo HTML::a(Yii::$app->imageCache->thumb($node->image, 'post', ['class' => 'img-responsive']), ['post/view', 'slug' => $node->slug]);
    ?>
<h4 class="partner-item-heading"><?php 
    echo HTML::a($node->title, ['post/view', 'slug' => $node->slug]);
    ?>
</h4>
    <?php 
    echo BaseStringHelper::truncateWords($node->content, 50);
    ?>
	
</div>
<?php 
}
?>

<div class="pagi">
    <?php 
echo \yii\widgets\LinkPager::widget(['pagination' => $pagination, 'options' => ['class' => 'pagination small']]);
?>
</div>
</div>
</div>
Пример #4
0
    echo \yii\helpers\BaseStringHelper::truncateWords($news->title, $titleLength);
    ?>
                                </h4>
                                <div class="image-container">
                                    <img class="image" alt="<?php 
    echo $news->title;
    ?>
" src="<?php 
    echo $news->imagePreview;
    ?>
">
                                </div>
                            </a>
                            <p class="nspText longText">
                                <?php 
    echo \yii\helpers\BaseStringHelper::truncateWords(strip_tags($news->getTextPreview(0), '<a></a>'), $textLength);
    ?>
                                <a class="readon inline" href="<?php 
    echo $news->fullLink;
    ?>
">Подробнее</a>
                            </p>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>
<?php 
}
Пример #5
0
Pjax::begin();
?>
        <div class="box-body">

            <!-- Global Search -->
            <?php 
// echo $this->render('_search', ['model' => $searchModel]);
?>
            <p><?php 
echo Html::a("Refresh", ['product/index'], ['class' => 'btn btn-md btn-default']);
?>
</p>

            <?php 
echo GridView::widget(['dataProvider' => $dataProvider, 'filterModel' => $searchModel, 'tableOptions' => ['class' => 'table table-striped table-bordered'], 'columns' => [['attribute' => 'title', 'contentOptions' => ['style' => 'width: 20%;']], ['attribute' => 'description', 'value' => function ($model) {
    return BaseStringHelper::truncateWords($model->description, 15);
}], ['label' => 'Image', 'format' => 'raw', 'value' => function ($model) {
    return \common\components\Product::getSmallProductImage($model);
}], ['attribute' => 'category_id', 'value' => function ($model) {
    return empty($model->category_id) ? '-' : $model->category->title;
}], 'price', ['header' => 'Actions', 'class' => 'yii\\grid\\ActionColumn', 'template' => '{view} {update} {images} {delete}', 'buttons' => ['images' => function ($url, $model, $key) {
    return Html::a('<span class="glyphicon glyphicon glyphicon-picture" aria-label="Image"></span>', Url::to(['image/index', 'id' => $model->id]));
}], 'contentOptions' => ['style' => 'width: 10%;']]]]);
?>

        </div>
        <!-- /.box-body -->
        <?php 
Pjax::end();
?>
Пример #6
0
<?php

/**
 * @var yii\web\View $this
 * @var app\models\Book $model
 * @var int $key
 * @var int $index
 * @var \yii\widgets\ListView $widget
 */
use yii\helpers\Html;
$title = $model->title;
$link = Html::a($title, ['front/view', 'alias' => $model->alias], ['data-pjax' => 0]);
$description = \yii\helpers\BaseStringHelper::truncateWords($model->description, 10);
$photo = $model->photo ? Html::img($model->photo) : '';
$authors = array_map(function ($modelAuthor) {
    /** @var app\models\Author $modelAuthor */
    return $modelAuthor->name;
}, $model->authors);
$authors = join(', ', $authors);
$tags = array_map(function ($modelTag) {
    /** @var app\models\Tag $modelTag */
    return $modelTag->title;
}, $model->tags);
$tags = join(', ', $tags);
?>

<div class="row">
    <div class="col-md-12">
        <h3><?php 
echo $link;
?>