Anyone using angular and Yii 2 together? I’m wondering if you could share your setup and philosophy. I have read about a few different approaches:
-
Using Yii as REST api backend only. Serve all frontend code from a static CDN, or even from the same frontend server but totally separate
-
Loading Angular as part of an asset bundle - one big single-page app (SPA)
I like the idea of still using Yii’s frontend code for the backend of my site (admin stuff) since it doesn’t really need to be fancy. Likewise, it seems like a lot of extra work and perhaps bad practice to use angular for the public-facing parts of my site since they consist mainly of information and semi-static content. As I understand, SEO is non-trivial with a SPA. It is really the logged-in, customer-facing portion that I think a SPA would enhance the experience. So I’m sort of leaning towards the second approach I have listed.
Where I get a little fuzzy on how it will work…
I’m thinking I will still need to build REST endpoints in Yii for the client based app. Or, is there a better way to accomplish this without a lot of code duplication? Can you provide an activerecord-based response and REST response from the same controller, using the same base model?
How would auth be handled? From what I read it sounds like best practice is to use some sort of token-based auth, OAuth, JWT, etc. What does Yii offer that would help with auth in this scenario?
Thanks to all who reply.