If my application have api, frontend and backend, how can I solve same code? In Yii2 advanced I can write in common, but how to do this in yii template mode?
That is request/response and middleware approach. The idea is documented.
In Yii 2 alike (but slightly limited) approach with request/response could be used.
The difference with simplified approach is that you’re getting request from Yii::$app->request, setting headers with Yii::$app->response and doing data/string returns (which, in fact are wrapped into response under the hood).
There are already dependencies to yii and its parts.
I am not sure what kind of dependencies you mean?
In any case, there should be examplery code for console, web and maybe rest api.
Maybe the web and restapi could be done with a Gii like generator. E.g. you want to add a blog, easy - goto app generator.
One issue you linked is about the user expecting a index.php, well no idea there. I think create-project should make something which usable from start, gives a better feeling specially for first time users. But could also be “yii init” script doing that.
The other issue is about libraries, using vue or vanilla js or angular - those differ drasticaly.
It would be nice if this is in a separate package, and not bundled.
If I make a console app, I dont need it, same for API. And if I want make web app I can use it then.
Vanilla JS should be default. And a external package which can enhance that.
Voting for make it simpler, multiple templates are tedious to mantain, and I dont see any advantage. I had say, make Gii generator for that.
One key feature of (advanced at least) - deployability / maintainability. I added an API “section” (@api) to advanced in under an hour for example that pulls in all my core models in @common and just requires 1-2 controllers to build out a complete functional API. Could it be easier? Sure, but having a consistent interface for deployment and updates (checkout -> composer install -> ./yii migrate) should not be overlooked. The trouble is not starting a project - the trouble is not cratering it with mistakes after it is up and running.
The advantage to the current templates is that they have a consistent, maintained, explicit structure which is predictable enough that I can write Ansible scripts around it, for example. Just having a “demo” is not the same thing as having a deployable application I can hand to devops and not have to spend the next two weeks creating scaffolding from scratch…
The utility of the current templates should not be overlooked - they are actually fairly simple from that perspective vs. some other approaches I have seen, which actually makes the templates quite useful. If there is confusion due to the “complexity”, the answer is probably better docs or how-tos, not removing the feature.
That’s all fine, but really I’m not sure if anyone would be happy doing it this way. Most people are used to doing it the “simplified” way, and I don’t just mean Yii users, I’m talking about Laravel, Symfony, Cake, etc.
Now when you create a new controller and want to render a view, you will probably not remember the render code and have to copy and paste it from another controller.
Yes, we can create out own render function that wraps all that logic up, but really we should not have to do this. I think many users will be put off by this approach.
The question is whatever we prefer plain simple templates vs package inheritance. For example, yii-base-web will magically add some routes and their implementation to the application. yii-base-cli will add some console commands etc. In order to remove/adjust these you’ll have to override some configs.
I can see already questions, how can I enable cli in in my base-web, or how can I enable web in my cli?
If its possible to make it “combined” … would be nice.
We could move on with generator approach. Then we could have one template, which is almost empty by default, but could easily generate endpoints using command line (provided by separate package). Like vendor/bin/yiiapp web frontend generates web endpoint under fronted directory and vendor/bin/yiiapp rest api will generate REST API endpoint under api directory. It could be even extended to use community templates (vendor/bin/yiiapp rob006/fancy-web-template fronted).