dtwzwmv87399 2013-11-14 21:10
浏览 6

在CodeIgniter中构建一个菜单

main_view

<table width="1100" border="1" align="center">
  <tr><?php $this->load->view('header_view'); ?></tr>
  <tr><?php $this->load->view('menu_view'); ?></tr>
  <tr>
    <td colspan="2"  id="content">
      <?php
            $a = ($_GET['pages/']);
            switch($a)
        {
                case "home":
                  require("pages/home");
                  break;
                case "about":
                  require("pages/about");
                  break;
         }
         ?>
    </td>
    <?php $this->load->view('rightMenu_view'); ?></tr>
  <tr><?php $this->load->view('footer_view'); ?></tr>
</table>

menu_view

 <div id="menu">
    <ul>
        <li><a href="pages/home">Home</a></li>
        <li><a href="pages/about">About</a></li>
        <li><a href="pages/staff">Staff</a></li>
        <li><a href="pages/chat">Chat</a></li>
        <li><a href="pages/championat">Championat</a></li>
        <li><a href="pages/contact">Contact</a></li>
    </ul>
</div>

pages_controller

class Pages extends CI_Controller
{
    public function __construct()
    {
        parent::__construct();
        $this->load->helper('html');
        $this->load->helper('url');
        $this->load->helper('form');
    }
    public function index()
    {
        $this->load->view('main_view');
    }
    public function home() { echo "Hello"; }
    public function about() { echo "Hello about"; }
}

I want to switch to other option in menu and only change the column td id="content" with the content. But it doesn't work.

I think the error is at switch.

I did something similar but I have not ever used a framework

  • 写回答

1条回答 默认 最新

  • doujiao7483 2014-02-22 11:15
    关注

    Firstly, it isn't semantic HTML to use tables as a formatting method. it is best to avoid it.

    codeigniter has a $this->input->get('variablename'); which is a bit more secure than $_GET(), and returns FALSE if the GET is not set.

    a get call in the URL requires ?name1=value1 in the URL. you are not using this, which is probably why it is not working.

    CI does allow parameters in controller methods. look into it, you can put the switch in your Pages::index method.

    评论

报告相同问题?

悬赏问题

  • ¥20 win11修改中文用户名路径
  • ¥15 win2012磁盘空间不足,c盘正常,d盘无法写入
  • ¥15 用土力学知识进行土坡稳定性分析与挡土墙设计
  • ¥70 PlayWright在Java上连接CDP关联本地Chrome启动失败,貌似是Windows端口转发问题
  • ¥15 帮我写一个c++工程
  • ¥30 Eclipse官网打不开,官网首页进不去,显示无法访问此页面,求解决方法
  • ¥15 关于smbclient 库的使用
  • ¥15 微信小程序协议怎么写
  • ¥15 c语言怎么用printf(“\b \b”)与getch()实现黑框里写入与删除?
  • ¥20 怎么用dlib库的算法识别小麦病虫害