Application template


(kriss) #3

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?


(kriss) #4

I think people can write a BaseController, and a render function to solve this, but this is not simpler


(Alexander Makarov) #5

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).


(Alexander Makarov) #6

Similar way.


#7

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.


(mikem) #8

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.


(Alexander Makarov) #9

Sure. Demo is just an example, it’s not a template that we’re going to ship with alpha version.


#10

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.


(Alexander Makarov) #11

This thing? I was going to move it to yii-web package.


(Schmunk) #12

The question is, what is simpler? Just to have a website by default?
The possibility to not have that was brought up in another design discussion.

Several users wanted to be able to start with no assumptions made in advance and ie. just create an API with a CLI.

Adding the web-part to the project template should just be one command, in theory :slight_smile:

It would also be nice, if yii-demo was created from yii-project-template which is AFAIK not the case.


(Alexander Makarov) #13

It’s not the case because yii-project-template is currently outdated.


(Alexander Makarov) #14

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.


#15

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.


(Alexander Makarov) #16

That’s why I dislike current template :frowning: base-web is not a template, it is used by template.


(Schmunk) #17

Yeah, base-web, base-api and other bases are merely entrypoints.


(Schmunk) #18

I’d vote for keeping the project-template without any code (like it is atm), but build examples like yii2-app-basic or yii2-app-advanced from it.


#19

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).


(Alexander Makarov) #20

Or we can revert to plain template approach such as yii-app-basic. Without any base packages or composition or generation (except gii).


(jomonjohnson) #21

what about symfony skelton,
can include required app templates as composer require dependencies?


(Alexander Makarov) #22

Yes. That is possible as well and that’s actually how current template is built. But it seems it leads to no good in our case because it seems to be very confusing.