yiisoft / yii2-collection Goto Github PK
View Code? Open in Web Editor NEWCollection extension for Yii 2
License: BSD 3-Clause "New" or "Revised" License
Collection extension for Yii 2
License: BSD 3-Clause "New" or "Revised" License
Can't you use
int iterator_count ( Traversable $iterator )
http://php.net/manual/en/function.iterator-count.php
?
http=>https
Q | A |
---|---|
Yii version | |
Yii Collection version | |
PHP version | |
Operating system |
The current implementation of GeneratorCollection
supports functions like filter
and map
.
Doing something like I've proposed here: nikic/iter#45
Would allow for a fluent interface allowing code like
$collection->filter(...)->map(....)->...
Yii 2 requires PHP 5.4, but this requires at least 5.5, I'd suggest, if you are using a stricter requirement than Yii 2 anyway, to just go with 7.0 or 7.1. (Since that is where Yii 2.1 will go as well)
Q | A |
---|---|
Yii version | |
Yii Collection version | |
PHP version | |
Operating system |
Q | A |
---|---|
Yii version | |
Yii Collection version | |
PHP version | |
Operating system |
Q | A |
---|---|
Yii version | |
Yii Collection version | |
PHP version | |
Operating system |
ArrayAccessTrait
apply()
: calls given method for each object in collectionhttps://gist.github.com/WinterSilence/b1884de728d3023591bf6e0c53181742
Right now basic CRUD for model looks like this:
public function actionCreate()
{
$model = new User();
if ($model->load(Yii::$app->request->post()) && $model->save()) {
return $this->redirect(['view', 'id' => $model->id]);
} else {
return $this->render('create', [
'model' => $model,
]);
}
}
public function actionUpdate($id)
{
$model = $this->findModel($id);
if ($model->load(Yii::$app->request->post()) && $model->save()) {
return $this->redirect(['view', 'id' => $model->id]);
} else {
return $this->render('update', [
'model' => $model,
]);
}
}
public function actionDelete($id)
{
$this->findModel($id)->delete();
return $this->redirect(['index']);
}
When we need to work with tabular input and handle multiple instances of the same model in single request, things get more complicated (and still there is no docs for it).
ModelCollection
could provide wrappers that makes this similar to CRUD for single model:
public function actionCreate()
{
$collection = (new PostCollection())->fill(Post::className(), 10);
if ($collection->load(Yii::$app->request->post()) && $collection->save()) {
return $this->redirect(['index']);
} else {
return $this->render('create', [
'collection' => $collection,
]);
}
}
public function actionUpdate($ids)
{
/* @var $collection PostCollection */
$collection = $this->findModels($ids);
if ($collection->load(Yii::$app->request->post()) && $collection->save()) {
return $this->redirect(['index']);
} else {
return $this->render('update', [
'collection' => $collection,
]);
}
}
public function actionDelete($ids)
{
$this->findModels($ids)->delete();
return $this->redirect(['index']);
}
http=https
Q | A |
---|---|
Yii version | |
Yii Collection version | |
PHP version | |
Operating system |
https://github.com/yiisoft/yii2-collection/blob/master/src/ModelCollection.php#L55
Q | A |
---|---|
Yii version | 2.0.15.1 |
Yii Collection version | dev |
PHP version | 7.2 |
Operating system | linux |
The following issue could probably be solved by using collection:
yiisoft/yii2#2900
Q | A |
---|---|
Yii version | |
Yii Collection version | |
PHP version | |
Operating system |
Basic project infastructure should be setup, allowing early access and contributing.
Following action should be performed:
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.