Download the PHP package sjaakp/yii2-wordcount without Composer

On this page you can find all versions of the php package sjaakp/yii2-wordcount. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package yii2-wordcount

Yii2-wordcount

Word count behavior for Yii2

Latest Stable Version Total Downloads License

This is a word counting behavior for ActiveRecords in the Yii 2.0 PHP Framework. It counts the words in one or more designated attributes. The count(s) are exposed through new virtual attributes.

A demonstration of yii2-wordcount is here.

Installation

The preferred way to install yii2-wordcount is through Composer. Either add the following to the require section of your composer.json file:

"sjaakp/yii2-wordcount": "*"

Or run:

composer require sjaakp/yii2-wordcount "*"

You can manually install yii2-wordcount by downloading the source in ZIP-format.

Using WordCount

WordCount is a Behavior for an ActiveRecord. It has one property:

If the count attribute name is not explicitly set in the $attribute array, the virtual count attribute is called '<attrName>_count' automatically.

Here is the simplest way to set up an ActiveRecord with WordCount:

namespace app\models;

use yii\db\ActiveRecord;
use sjaakp\wordcount\WordCount;

class Article extends ActiveRecord
{
    public static function tableName()
    {
        return 'article';
    }
    // ...

    public function behaviors()
    {
        return [
            [
                'class' => WordCount::class,
                'attribute' => 'bodytext'
            ],
            // ... other behaviors ...
        ];
    }
    // ...
}

Class Article will now have a new virtual attribute with the name 'bodytext_count'. It's value is an integer and it can be queried just like any other attribute:

$wordsCounted = $model->bodytext_count

A slightly more involved way to set up an Activerecord with WordCount would be:

 // ...     
 class Article extends ActiveRecord
 {
     // ...

     public function behaviors()
     {
         return [
             [
                 'class' => WordCount::class,
                 'attribute' => [
                    'bodytext' => 'textcount',
                    'title' => 'titlecount'
                 ]
             ],
             // ... other behaviors ...
         ];
     }
     // ...
 }

It gives two new virtual attributes, named 'textcount' and 'titlecount'.

Notice that WordCount uses the PHP function str_word_count(). This is not the most perfect way to count words, so you should consider the results as no more than good approximations.

Totals

Totals is a helper class with one method:

public static function count($query, $attribute)

This static function returns the total of $attribute values in the ActiveRecords found by ActiveQuery $query. If $attribute is a string, the return value will be an integer. If $attribute is an array of attribute names, count() will return an array with '<attr>' => <total> elements.

Usage example:

use sjaakp\wordcount\Totals;

$totals = Totals::count(Article::find(), [ 'titlecount', 'textcount' ]);

Notice that count() also works with non-virtual attributes. However, it would be much wiser to use [ActiveQuery::sum()](https://www.yiiframework.com/doc/api/2.0/yii-db-query#sum()-detail) in that case.


All versions of yii2-wordcount with dependencies

PHP Build Version
Package Version
Requires yiisoft/yii2 Version *
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package sjaakp/yii2-wordcount contains the following files

Loading the files please wait ....