我有返回json响应的代码,但我不知道如何在php函数中传递该值。如何将angularjs数组值作为变量传递给php函数?
代码:
<div class="container" ng-controller="askbyctrl" >
<div class="row" ng-repeat="q in qa.data" >
<div class="col-md-12 col-xs-12 col.sm.12" >
<div class="artist-data pull-left" style = "background-color:#BEB7B7;">
<div class="artst-pic pull-left">
<?php
function cache_image($id){
//replace with cache directory
$image_path = 'C:\xampp\htdocs\QA_UI\images';
$image_url = 'http://localhost:8000/api/image/' + id;
//get the name of the file
$exploded_image_url = explode("/",$image_url);
$image_filename = 'id.jpg';
$exploded_image_filename = explode(".",$image_filename);
$extension = end($exploded_image_filename);
//make sure its an image
if($extension=="jpg") {
//get the remote image
$image_to_fetch = file_get_contents($image_url);
if($image_to_fetch == '{"error":true,"details":"No image."}') {
echo 'file not found';
} else {
//save it
$local_image_file = fopen($image_path.'/'.$image_filename, 'w+');
chmod($image_path.'/'.$image_filename,0755);
fwrite($local_image_file, $image_to_fetch);
fclose($local_image_file);
echo 'copied';
}
}
//}
?>
<img ng-src="images/{{q.userID}}.jpg" alt="" class="img-responsive" />
</div>
请参阅PHP函数的代码我怎样才能通过{{q.userID}} ..
你有没有想过ajax – Gowri 2014-09-02 06:35:34
我不知道我该怎么做,如果你有请求告诉我,我是angularJs的新手,我不知道如何在angularJs中使用php代码。 ..我不知道我必须编写seprate控制器采取php代码或我可以直接使用... – 2014-09-02 06:39:03
您不能使用客户端代码内的服务器端代码。但是,您的客户端可以使用ajax调用来调用资源,并且该资源可以包含使用php呈现的文档。 – sensorario 2014-09-02 06:50:39