Download the PHP package mobileka/scope-applicator-yii2 without Composer

On this page you can find all versions of the php package mobileka/scope-applicator-yii2. 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 scope-applicator-yii2

Build Status Code Climate Coverage Status

ScopeApplicator brings an elegant way of sorting and filtering data to your Yii2 projects.

Overview

ScopeApplicator is an easy and logical way to achieve something like this:

/posts – returns a list of all posts

/posts?recent – returns only recent posts

/posts?author_id=5 – returns posts belonging to an author with an id=5

/posts?author_id=5&order_by_title=desc&status=active – returns only active posts belonging to an author with an id=5 and sorts them by a title in a descending order

Requirements

– PHP 5.4 or newer

– Yii 2.0.x

Installation

composer require mobileka/scope-applicator-yii2 1.0.*

Usage

Let's learn by example. First of all, we'll implement an author_id filter for post table.

These are steps required to achieve this:

  1. Create a PostQuery class which extends Mobileka\ScopeApplicator\Yii2\ActiveQuery and define a userId method
  2. Create a Post model which extends Mobileka\ScopeApplicator\Yii2\Model and make it use the PostQuery instead of a regular ActiveQuery
  3. Create a basic PostController which outputs a list of posts when /posts route is hit
  4. Tell ScopeApplicator that userId scope is available and give it an alias
  5. Visit /posts?author_id=1 and enjoy the result

Ok, let's cover these step by step.

— Create a PostQuery class in app/models/queries directory with the following content:

I'll refer the userId() method as a userId scope in the future.

Make sure that this class extends Mobileka\ScopeApplicator\Yii2\ActiveQuery.

– Create a Post model and override the find method like follows:

This makes sure that our userId scope will be available to the Post model.

– Next, create a PostController:

In this case I extend the yii\rest\Controller and make sure that its output format is set to JSON.

– Now let's modify this controller to make it use ScopeApplicator:

Note that I added a new protected property which describes available scopes. Right now we have only userId.

Also note that I have replaced Post::find() with Post::applyScopes($this->scopes).

If you have done all the above steps, you should be able to populate your post table and try to filter data like follows: /posts?userId=x.

But we wanted it to be author_id instead of userId, so we have to configure our scope and add an alias:

— That's it! Now you can visit /posts?author_id=x and check the result.

alias is only one of the many available scope configuration options. These are described in ScopeApplicator's documentation.

Contributing

If you have noticed a bug or have suggestions, you can always create an issue or a pull request (use PSR-2). We will discuss the problem or a suggestion and plan the implementation together.

License

ScopeApplicator is an open-source software and licensed under the MIT License.


All versions of scope-applicator-yii2 with dependencies

PHP Build Version
Package Version
Requires php Version >=5.4.0
mobileka/scope-applicator Version 1.1.*
yiisoft/yii2 Version 2.0.*
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 mobileka/scope-applicator-yii2 contains the following files

Loading the files please wait ....