0

How to build web application in Angular2 + Yii2 ?

I have good knowledge in both technology. But, how to communicate Angular2 + Yii2.

I know one way to communicate angular2 + yii2 using REST Api. But, one problem in yii2 for Cross-origin issue. this way in run client & server both are separately.

Is it possible to start/run angular2 from the index.php for the yii2?

Any idea or web link about this. Please, share with me.

Bharat Chauhan
  • 3,204
  • 5
  • 39
  • 52

1 Answers1

0

If you are going to use Yii2 forn just RESTApi, then, you will need 2 project, frontend froject for Angular2, and backend project for Yii2

For Yii2, simple add header to index.php, so can prevent Cross-origin

header("Access-Control-Allow-Origin: *");
header("Access-Control-Allow-Headers: Cache-Control, Pragma, Origin,Authorization, Content-Type, X-Requested-With, loginToken");
header("Access-Control-Allow-Methods: GET,POST,PUT,DELETE");

For angular2, if you dont family with it, and frontend project, you can use some tool to generate your project. http://yeoman.io/ is an example

Vo Kim Nguyen
  • 1,613
  • 10
  • 14
  • i know about header configuration. But, Is it possible Yii2 index.html or index.php starting point for angular2? – Bharat Chauhan Dec 15 '16 at 14:21
  • 1
    there is a built-in filter for that if you want to control it within Controller instead of entry script. see http://www.yiiframework.com/doc-2.0/yii-filters-cors.html – Salem Ouerdani Dec 15 '16 at 14:42