Answer the question
In order to leave comments, you need to log in
Static use methods?
Is there anything like this in puff?
To then use static methods without specifying the class name. Many languages have this ... I would very much like to. use static yii\helpers\ArrayHelper\*;
Answer the question
In order to leave comments, you need to log in
1. You initiate the data load after the component mounts, but assign the state before.
2. In your case, you do not need to store data in the component's state at all.
3. By changing the filtering / sorting parameters, in a good way, a new request should occur with the appropriate parameters.
why do you even put data from the store into the container state? pass directly the value from the store
No. And I do not understand your desire. A static method differs from a simple function in that when the method is called, it is visible to which class it belongs. This is good, because you may have several classes that have static methods with the same name, for example BlogPostAR::find()
and CommentAR::find()
.
The same applies to helpers. Several libraries may provide their own helpers for similar tasks.
And if you are too lazy to type the class name - ok, use as :
use yii\helpers\ArrayHelper as ah;
ah::toArray($obj);
ArrayHelper::toArray()
, because everyone who works with yii is used to it.
Purely for reference, do not use in real code
<?php
function getStatic($c){
$r = [];
foreach((new ReflectionClass($c))->getMethods(ReflectionMethod::IS_STATIC | ReflectionMethod::IS_PUBLIC) as $v){
$r[$v->name] = $v->class.'::'.$v->name;
}
return $r;
}
class Test{
static function hello(){
echo "hello\n";
}
static function world($p){
echo "world $p\n";
}
}
extract(getStatic('Test'));
echo '<pre>';
$hello();
$world(42);
echo '</pre>';
?>
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question