如何将PHP与Yeman角度项目集成
我正在使用 yeoman 项目的问题, angularjs 的问题通常我知道如何在正常的PHP上使用angularjs项目.
I'm using yeoman project using angularjs normally I know how to use angularjs with PHP on normal projects.
但是我很困惑将php与yeoman一起使用.
But I'm confused to use php with yeoman.
我应该在哪里创建.php
文件,如何在main.js
控制器中调用$http
范围?
Where should I create .php
file and how should I call $http
scope in main.js
controller?
如果使用的是generator-angular,则需要两个元素:
If you're using generator-angular, you need two elements:
1/在像public
这样的子目录中,您的PHP可以正常运行,因此当您进入http://localhost/
1/ Have your PHP running as you would normally in a subdirectory like public
so public/index.php
is loaded when you go to http://localhost/
2/使用Grunt任务将src
中的各个AngularJS源文件编译成单个文件,例如public/js/myapp.js
,然后在public/index.php
中添加类似<script src="/js/myapp.js></script>
2/ Use a Grunt task to compile the individual AngularJS source files in src
into a single file somewhere like public/js/myapp.js
and in public/index.php
add something like <script src="/js/myapp.js></script>
3/如果要向Angular应用发送JSON,请使用json_encode
,例如:
3/ If you're wanting to send JSON to your angular app, use json_encode
such as:
<?php
header('Content-type: application/json');
echo json_encode($someArray); ?>
?>
您还可以查看 grunt-php ,以便在一个开发箱.
You could also have a look at grunt-php for serving up you PHP files on a dev box.
无耻的自我插件-我还编写了一个生成器,该生成器使用FlightPHP后端创建了一个简单的AngularJS应用程序: https://npmjs.org/package/generator-flightangular -这可能使您了解如何从PHP后端拆分JavaScript元素.
Shameless self plug - I've also written a generator that creates a simple AngularJS app with a FlightPHP backend: https://npmjs.org/package/generator-flightangular - Which might give you an idea of how you can split the JavaScript elements from the PHP backend.