我在控制器中创建菜单,只想在视图中显示该菜单(在我的例子中它是一个元素)但问题是控制器创建的菜单部分没有附加到已经创建的部分在视野中。我不太了解在控制器中创建HTML代码以及在Cakephp中在视图中呈现。请帮助解决我的问题。我的代码段是:
控制器代码:
public function sub_categories($id){
$categories = $this->Categories->find('all',array('conditions'=>array('parent IN'=>$id)))->toArray();
$i=0;
foreach($categories as $p_cat){
$cat_id=$p_cat['category_id'];
$categories[$i]['sub'] = $this->sub_categories($cat_id);
$i++;
}
return $categories;
}
public function get_categories()
{
$categories = $this->Categories->find('all',array('conditions'=>array('parent IN'=>'0')))->toArray();
$i=0;
foreach($categories as $p_cat){
$categories[$i]['sub'] = $this->sub_categories($p_cat['category_id']);
$i++;
}
return $categories;
}
public function fetch_menu($data){
foreach($data as $menu){
echo "<li class='dropdown menu__item'>";
echo "<a href=# class='dropdown-toggle menu__link' data-toggle='dropdown' role='button' aria-haspopup='true' aria-expanded='false'>".$menu->category_name."<span class='caret'></span></a>";
if(!empty($menu->sub)){
echo "<ul class='dropdown-menu multi-column columns-3'>";
echo "<div class='agile_inner_drop_nav_info'>";
echo $this->fetch_sub_menu($menu->sub);
echo "<div class='clearfix'></div>";
echo "</div>";
echo "</ul>";
}
echo "</li>";
}
}
public function fetch_sub_menu($sub_menu){
foreach($sub_menu as $menu){
echo "<div class='col-sm-3 multi-gd-img'>";
echo "<ul class='multi-column-dropdown'>";
echo "<li><a href='mens.html'>";
echo $menu->category_name;
echo "</a></li>";
echo "</ul>";
echo "</div>";
if(!empty($menu->sub)){
echo "<ul class='multi-column-dropdown'>";
echo "<li>";
echo $this->fetch_sub_menu($menu->sub);
echo "</li>";
echo "</ul>";
}
}
}
public function display()
{
$data = $this->get_categories();
$menu=$this->fetch_menu($data);
$this->set(compact('menu'));
}
查看代码:
<li class=" menu__item"><a class="menu__link" href="#">About</a></li>
<?php
echo $menu;
?>....
答案 0 :(得分:-1)
请像这样更新你的fetch_menu函数 在这里,我只是替换了你的&#34; echo&#34;带有双引号的变量和单引号以及带单引号的双引号。并返回变量
class ViewController: UIViewController,UIToolbarDelegate {
private var toolItems : [UIBarButtonItem] = []
override func viewDidLoad() {
super.viewDidLoad()
}
override func viewWillAppear(_ animated: Bool) {
navigationController?.isToolbarHidden = false
let height: CGFloat = 130
let bounds = self.navigationController?.toolbar.bounds
navigationController?.toolbar.barTintColor = UIColor(red: 0.0/42, green: 0.0/42, blue: 0.0/56, alpha: 1)
navigationController?.toolbar.tintColor = UIColor.white
navigationController?.toolbar.frame = CGRect(x: 0, y: self.view.frame.height - 80, width: self.view.frame.width, height: (bounds?.height)! + height)
navigationController?.toolbar.isTranslucent = false
navigationController?.toolbar.heightAnchor.constraint(equalToConstant: (bounds?.height)! + height).isActive = true
navigationController?.toolbar.sizeToFit()
let btn_Tracking = UIButton(type: .custom)
btn_Tracking.setImage(UIImage(named: "icon-trackingtabbed@2x"), for: .normal)
btn_Tracking.sizeToFit()
let trackingItem = UIBarButtonItem(customView: btn_Tracking)
///Sign
let btn_sign = UIButton(type: .custom)
btn_sign.setImage(UIImage(named: "icon-trackingtabbed@2x"), for: .normal)
btn_sign.sizeToFit()
let sginItem = UIBarButtonItem(customView: btn_sign)
let fixedSpace: UIBarButtonItem = UIBarButtonItem(barButtonSystemItem: UIBarButtonSystemItem.fixedSpace, target: nil, action: nil)
fixedSpace.width = 10.0
let flexibleSpace: UIBarButtonItem = UIBarButtonItem(barButtonSystemItem: UIBarButtonSystemItem.flexibleSpace, target: nil, action: nil)
self.toolbarItems = [flexibleSpace,sginItem,flexibleSpace,trackingItem,flexibleSpace]
}
}