Firstly a big thank you to everyone involved in Yii. It’s a fantastic framework, very well designed, fast and incredibly flexible.
For the past 2 years I’ve used Yii2 for building many application for clients. As part of those projects, I have developed a lot of additional functionality which may be of interest to include or at least think about for Yii 3.0.
ActiveRecord is awesome, but it can be better
I’d like to see the concept of a
fieldType that provides default
load() methods for pre/post processing of database data into a PHP format along with various metadata relating to the field.
You can see an implementation of this in Yii2 here:
The concept of scenarios in Yii2 was new to me and it makes so much sense. In fact, I think it’s use should be expanded to be aligned with any action including
index actions so an autogenerated CRUD layout can be generated using the fields in those scenarios.
Models have actions that have URL’s. A
getUrl() method on a Model works really well and simplifies URL creation across most of the application.
The current RBAC implementation is rather complicated to understand and configure while it heavily uses the database which isn’t particularly performant. It also only restricts access to controllers and not the underlying database.
The features I would like to see:
- Only roles stored in the database for increased performance and no need to support migrations
- Expand RBAC support to ActiveRecord to restrict access closer to the database for increased security and consistency of security rules across web and api applications.
- Support security policies / rules that generate a filter to apply to the database to dynamically restrict result sets or database updates – this provides huge flexibility and leverages the performance of the database to do a lot of heavy lifting.
- Leverage Yii’s excellent configuration mechanism to quickly configure permissions
- Support controller inheritance so security policies attached on a parent are inherited by a child
- Support configuration file to override default RBAC configuration defined within controllers
I have almost finished porting across code that does most of this in Yii2 here: https://github.com/Mozzler/yii2-rbac
I would like to see widgets support a convention of auto-locating of relevant widget files. ie: You may have PanelWidget.php, PanelWidget.css, PanelWidget.js where the .css and .js are auto-loaded if they exist.
You can see a primitive implementation of this here:
Yii2’s Gii takes the approach of building CRUD controllers, views etc. as part of the build. I want to dynamically build the CRUD and allow for easily redesigning / customising a core CRUD application.
For the most part I actually want the views to be inherited based on the Model inheritance hierarchy.
For example, if I create a
BaseModel with CRUD views (create, read, update, index) and then create a sub-model
BlogPostModel that inherits from
BaseModel, I would like those CRUD views to be “inherited”.
Under this approach, I could simply adjust the
index linked to
BaseModel to change the default template for all models in my application.
Extending this further,
BlogPostModel may exist in a third party extension and I have extended it further with two new models
Under this approach, I have complete control over customising the view templates for each of
MyTextPostModel… or alternatively I can customise the view templates of
BlogPostModel which will change both
MyTextPostModel at once… or alternatively I can customise
BlogPostModel view templates to change everything,.
This becomes very powerful with larger applications and especially when having a “base” set of CRUD templates that can be rapidly re-styled across a whole application for a new project.
Again, I have implemented this in Yii2, with an added bonus of merging in controller inheritance.
There’s a lot there and I’ve put these notes down quickly, so hopefully they make some sense!
Let me know if there’s any interest in the above and I may be able to free up some time to implement the above in Yii3.