我正在将数据从控制器发送到codeigniter中的视图,在我传递$this->数据[城市监测]。
这是控制器
public function index() {
$this->data['ptype'] = "index";
if($this->validlang){
$slug = $this->uri->segment(3);
}else{
$slug = $this->uri->segment(2);
}
if (!empty ($slug)) {
$this->dests_lib->set_destid($slug);
$this->data['details'] = $this->dests_lib->dest_details();
$this->data['title'] = $this->dests_lib->title;
$this->data['thumbnail'] = $this->dests_lib->thumbnail;
$this->data['date'] = $this->dests_lib->date;
$res = $this->Settings_model->get_contact_page_details();
$this->data['phone'] = $res[0]->contact_phone;
$this->data['langurl'] = base_url()."destinations/{langid}/".$this->dests_lib->slug;
$mustvisitedlocid = $this->data['details'][0]->related_cities;
$this->data['mustvisitedcities'] = $this->dests_lib->get_mustvisitedcity($mustvisitedlocid);
$this->setMetaData($this->data['details'][0]->location_meta_title,$this->data['details'][0]->location_meta_desc,$this->data['details'][0]->location_meta_keywords);
$this->theme->view('modules/destinations/dest_details', $this->data, $this);
}
else {
$this->listing();
}
}
问题是传递$this->数据["城市"]抛出了一些我找不到的错误。当我去掉这个,一切都很好。
我试着打印这个变量,数据就在那里,但我不可能把它传递给视图。
当我打印$this->数据[城市',我得到以下结果
Array ( [0] => stdClass Object ( [id] => 2642 [location] => Irkutsk [slug] => https://www.happyvoyaging.com/destinations/Irkutsk [thumbnail] => https://www.happyvoyaging.com/uploads/images/locations/thumbs/ ) [1] => stdClass Object ( [id] => 3067 [location] => Krasnojarsk [slug] => https://www.happyvoyaging.com/destinations/Krasnojarsk [thumbnail] => https://www.happyvoyaging.com/uploads/images/locations/thumbs/ ) [2] => stdClass Object ( [id] => 3554 [location] => Saint Petersburg [slug] => https://www.happyvoyaging.com/destinations/Saint Petersburg [thumbnail] => https://www.happyvoyaging.com/uploads/images/locations/thumbs/ ) [3] => stdClass Object ( [id] => 4081 [location] => Murmansk [slug] => https://www.happyvoyaging.com/destinations/Murmansk [thumbnail] => https://www.happyvoyaging.com/uploads/images/locations/thumbs/ ) [4] => stdClass Object ( [id] => 4131 [location] => Moscow [slug] => https://www.happyvoyaging.com/destinations/Moscow [thumbnail] => https://www.happyvoyaging.com/uploads/images/locations/thumbs/ ) )
鉴于我正在提取上述数据作为
<?php foreach($mustvisitedcities as $item){ ?>
<div>
<div>
<a href="<?php echo $item->slug;?>">
<div>
<div>
<div class="lazyload-wrapper">
<img src="<?php echo $item->thumbnail;?>" alt="<?php echo character_limiter($item->location,30);?>" data-pin-nopin="true">
</div>
</div>
</div>
<div>
<h4 color="#121416"><?php echo character_limiter($item->location,30);?></h4>
</div>
</a>
</div>
</div>
<?php } ?>
当我打印整个$this->数据,我得到这个
Array ( [ptype] => index [details] => Array ( [0] => stdClass Object ( [id] => 9416 [country] => Russia [location] => Russia [location_slug] => [location_desc] => [location_meta_title] => Russia [location_meta_keywords] => [location_meta_desc] => [location_img] => [location_thumb] => 502844_russian.jpg [related_cities] => 2642,3067,3554,4081,4131 [preferred_cities] => [latitude] => 61.5240 [longitude] => 105.3188 [user] => [status] => Yes ) ) [title] => Russia [thumbnail] => https://www.happyvoyaging.com/uploads/images/locations/thumbs/502844_russian.jpg [date] => [phone] => +918860709211 [langurl] => https://www.happyvoyaging.com/destinations/{langid}/Russia [mustvisitedcities] => Array ( [0] => stdClass Object ( [id] => 2642 [location] => Irkutsk [slug] => https://www.happyvoyaging.com/destinations/Irkutsk [thumbnail] => https://www.happyvoyaging.com/uploads/images/locations/thumbs/ ) [1] => stdClass Object ( [id] => 3067 [location] => Krasnojarsk [slug] => https://www.happyvoyaging.com/destinations/Krasnojarsk [thumbnail] => https://www.happyvoyaging.com/uploads/images/locations/thumbs/ ) [2] => stdClass Object ( [id] => 3554 [location] => Saint Petersburg [slug] => https://www.happyvoyaging.com/destinations/Saint Petersburg [thumbnail] => https://www.happyvoyaging.com/uploads/images/locations/thumbs/ ) [3] => stdClass Object ( [id] => 4081 [location] => Murmansk [slug] => https://www.happyvoyaging.com/destinations/Murmansk [thumbnail] => https://www.happyvoyaging.com/uploads/images/locations/thumbs/ ) [4] => stdClass Object ( [id] => 4131 [location] => Moscow [slug] => https://www.happyvoyaging.com/destinations/Moscow [thumbnail] => https://www.happyvoyaging.com/uploads/images/locations/thumbs/ ) ) [pageTitle] => Russia [metadescription] => Book sightseeing tours, attractions, visa and experiences in 500+ destinations at guaranteed low prices with handpicked reliable suppliers. [metakeywords] => Tours, Sightseeing and Things To Do around the World, Russia Visa agent in India, Russia Visa agent Delhi, Dubai Visa agent Delhi, Dubai Visa agent India )
尝试使用:
$data['variablename']=$examplevariable;$data['variablename2']="这是一个测试";
$this->负载->视图('hpname',$data(;
点击查看: