【发布时间】:2019-06-14 18:50:42
【问题描述】:
我正在尝试使用PHP 和angularjs 显示Wordpress 内容和图像,当我使用strip_tags 从响应数据中删除html 标记时,我得到了实际内容,但图像没有显示。
这是我得到的结果:
script.js:
<script>
function myctrl($scope,$http){
$scope.word = [];
$http.get('<?php echo site_url('Home/getword'); ?>').success(function($data){
$scope.word=$data; });
}
</script>
型号:
public function getword()
{
$this->db->select('post_content');
$this->db->from('wp_posts');
$this->db->where(array('ID' => 22));
$query = $this->db->get();
$result = $query->result_array();
foreach ($result as $key) {
$record = $key;
}
return $record;
}
控制者:
public function getword()
{
$data = $this->Data_model->getword();
$this->output->set_content_type('application/json')->set_output(json_encode($data));
}
查看:
<div ng-controller="myctrl">
<span>{{word}}</span>
</div>
这是我得到的结果:
// 1.6.9版本将success改为then后的Result截图:
The screen shot of the web browser The screen shot of the browser after strip_tags('the content', '' is applied)
【问题讨论】:
-
为什么要混合 PHP 和 AngularJS?通常你使用其中一个。
-
顺便说一句:我建议将您的代码粘贴到您的帖子中(格式化为代码) - 代码图像非常不舒服(并且无法复制和测试)。
-
根据您的建议,我复制粘贴代码,请检查代码。
标签: php angularjs wordpress script-tag