以下Codeigniter控制器在通过url访问时输出JSON。
Codeigniter控制器
function ttoday(){
$this->load->model('dashboard_stats');
$tours_today = $this->dashboard_stats->upcoming_tours();
$data_json = json_encode($tours_today);
echo $data_json;
}

Codeigniter模型
function upcoming_tours()
{
mysql_query("SET time_zone = '+3:00'");
$this->db->order_by('from_start_time','asc');
$this->db->where('DATE(from_start_time) = CURDATE()');
$this->db->where('from_start_time > DATE_SUB(NOW(), INTERVAL 90 MINUTE)');
$query = $this->db->get('tours');
return $query->result();
}

Angularjs控制器
translineClassic.controller('homeController', ['$scope', '$http', '$window', '$rootScope', function($scope, $http, $window, $rootScope){
$http.get('http://122.222.22.2/booking/public_html/admin/api/cities')
.success(function(result){
$scope.cities = result;
});
$http.get('http://122.222.22.2/booking/public_html/admin/api/ttoday')
.success(function(result){
$scope.tours = result;
});
}]);

编码Json
[{"tour_id":"4260","route_time":"121473438600","tour_route":"12","from_start_time":"2016-09-09 19:30:00","available_seats":"47","start_price":"800.00","additional":"0","book_online":"0","date_created":"2016-08-30 09:50:05"},{"tour_id":"4412","route_time":"111473438600","tour_route":"11","from_start_time":"2016-09-09 19:30:00","available_seats":"47","start_price":"800.00","additional":"0","book_online":"0","date_created":"2016-08-30 11:34:46"}]

在存储路径的数据库中。我们存储了tour_route id而不是路由名称。有一个单独的表存储路由,我可以使用以下代码获取路由名称。
function get_route_name($id){
$this->db->select('route_name');
$this->db->where('route_id', $id);
$query = $this->db->get('routes');
if ($query->num_rows() > 0)
{
$row = $query->row();
return $row->route_name;
}
}

使用上面显示的代码,我可以使用$http
获取angularjs来获取数据,然后与视图绑定。
当我需要显示路线名称时出现问题。但是我有tour_route,我可以使用php
函数在get_route_name()
中执行此操作,如何打印路径名而不是tour_route?我是否必须再次使用$http
?请帮帮我。我是angularJs的新手,任何帮助都将受到赞赏。
我的观点
<article class="result">
<div ng-repeat="tour in tours">
<div class="one-fourth heightfix"><img class="img-responsive" src="assets/images/translinebus.JPEG" alt="" /></div>
<div class="one-half heightfix">
<h3>{{ tour.tour_route }} <a href="javascript:void(0)" ng-click="showDetails = ! showDetails" class="trigger color" title="Read more">?</a></h3>
<ul>
<li>
<span class="ico people"></span>
<p>Max people</strong> <br/>
Seats Remaining </strong> </p>
</li>
<li>
<span class="ico luggage"></span>
<p>Max <strong>3 suitcases</strong> <br />per vehicle</p>
</li>
<li>
<span class="ico time"></span>
<p>Departure Time<br />
<strong><span class="icon-clock" style="color:red;">
{{ tour.from_start_time }} </span>
</strong></p>
</li>
</ul>
</div>
<div class="one-fourth heightfix">
<div>
<div class="price"><small>KES</small> {{ tour.start_price }}</div>
<span class="meta">per passenger</span>
<button value="{{ tour.tour_id }}" type="submit" class="btn grey large">select</button>
</div>
</div>
<div class="full-width information" ng-show="showDetails">
<a href="javascript:void(0)" class="close color" title="Close">x</a>
<p>Free Wifi, Charging</p>
</div>
</div>
</article>
&#13;