如何将PHP与Yeman角度项目集成 [英] How to integrate PHP with yeoman angular project

查看:75
本文介绍了如何将PHP与Yeman角度项目集成的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用项目的问题,的问题通常我知道如何在正常的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.

这篇关于如何将PHP与Yeman角度项目集成的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆