I wish I could create functions the way it did in 1.x Yii to a value of an array. How can I do this? Remember that this code is just an example and not the real situation. The function will be more complex than the above example …
Where do you define and how do you refer to your $configFields? If you define it in the controller and try to access it in the view by "$this->configFields", then it will not work.
Or, if you define it in the view script and use $this to refer to the controller, it also won’t work as expected.
Yes, it does. But only in the place where applicable. It has been the same with Yii 1.1. Your closure will do the job, for instance, for the value of a grid view column. But not always.
Where and how did you refer to the closure in Yii 1.1?
The example above works in 1.x Yii the controller and also the View.
You could write a small sample code as i do the key of an array receive an Anonymous function as in the previous example? Because I can not do this in Yii 2.x in the view or controller.
It doesn’t display “test”, but “Closure Object ( [this] => SiteController Object …” in Yii 1.1 app.
I did write your small sample code into a view code (and a controller code) of a Yii 1.1 app of my own, and confirmed it didn’t display “test”. Did you test your small sample code (as it is) in Yii 1.1?
That’s not what I wanted to know.
CDataColumn::value, for example, can take a function.