2011-02-28 92 views

回答

0

你應該只是路由鏈接到一個特定的控制器,處理菜單

+0

這裏的問題是管理員給他需要的菜單名稱和菜單鏈接..基於那特殊r控制器需要創建 – 2011-02-28 12:40:27

+0

我不明白爲什麼不能使用'(:any)'。這一切都可以成爲一個菜單。缺點是每個其他控制器(有效?)需要在路由中指定。 – 2011-02-28 14:33:48

1

當然,PyroCMS這樣做。看看模塊管理代碼,特別是details.php。您需要爲此進行一些開發,但我的代碼將演示我如何完成它。

http://github.com/pyrocms/pyrocms

1

我有這樣的工作了一段時間後很容易地..

看看我是怎麼做這個簡單的例子...這是一個幫助網站。

模型


<?php 

class Template_model extends Model { 

    function Template_model() 
    { 
     parent::Model(); 
    } 

    function load_pages() 
    { 
     $data = array(); 
     $this->db->where('status',0); 
     $this->db->order_by('sort', 'ASC'); 
     //$this->db->get('pages'); 
     $query = $this->db->get('pages'); 
     if ($query->num_rows() > 0){ 
      foreach ($query->result_array() as $row){ 
       $data[] = array(
        "name" => $row['name'], 
        "url" => $row['url'] 
       ); 
      } 
     } 

     $query->free_result(); 
     return $data; 
    } 

} 

控制器


<?php 

class View extends Controller { 

    function View() 
    { 
     parent::Controller(); 
    } 

    function index() 
    { 
     redirect('view/topic/orders'); 
     //echo "oops"; 
    } 

    function topic() 
    { 
     $page = $this->uri->segment(3); 

     //get the page id 
     $this->load->model('view_model'); 
     $id = $this->view_model->get_page_id_by_url($page); 
     $id = $id['id']; 

     //get the page title 
     $data['title'] = $this->view_model->get_page_title($id); 

     //load the post by page id 
     $data['posts'] = $this->view_model->get_page_posts($id); 

     //load the header 
     $this->load->model('template_model'); 
     $data['pages'] = $this->template_model->load_pages(); 

     //load the view 
     $data['main_content'] = 'view/page'; 
     $this->load->view('includes/template', $data); 

    } 

    function article() 
    { 
     $url = $this->uri->segment(3); 

     //get the post by url 
     $this->load->model('view_model'); 
     $data['post'] = $this->view_model->get_post_by_url($url); 
     $id = $data['post']['page_id']; 
     //print_r($data['post']); 

     //get the page title 
     $data['title'] = $this->view_model->get_page_title($id); 

     //load the post by page id 
     $data['posts'] = $this->view_model->get_page_posts($id); 

     //load the header 
     $this->load->model('template_model'); 
     $data['pages'] = $this->template_model->load_pages();  

     //load the view 
     $data['main_content'] = 'view/article'; 
     $this->load->view('includes/template', $data); 
    } 

} 

/* End of file view.php */ 
/* Location: ./system/application/controllers/view.php */ 

和視圖..


    <div id="navigation"> 
     <ul> 

       <?php 
       if(!empty($pages)) 
       { 
        foreach($pages as $page) 
        { 
         ?> 

          <li <?php if($on_page == $page['url']) { echo 'class="selected"'; }?>><a href="<?php echo base_url().'view/topic/'.$page['url'];?>"><?php echo $page['name'];?></a></li> 

         <? 

        } 
       }?> 

       <!-- top navigation use selected class for selected item --> 

       <div id="rNav" ><ul><li <?php if($on_page == 'admin') { echo 'class="selected"'; }?>><a href="<?php echo base_url();?>admin">Admin</a></li></ul></div> 
       <div id="rNav" ><ul><li <?php if($on_page == 'logout') { echo 'class="selected"'; }?>><a href="<?php echo base_url();?>logout">Logout</a></li></ul></div> 

     </ul> 
    </div> 

+0

我可以肯定,這是寫得不好,這是在我的早期,但動態網頁的概念在這個例子中工作得很好。 – Peter 2011-03-01 03:07:46

0

這裏是代碼,以使控制器和模型動態

代碼控制器

  $table="drill"; 
      $alias='*'; 
      $joinArgument=array 
      (
         array('tableName'=>'drillCategoryMaster', 
          'joinCondition'=>'drillCategoryMaster.drillCategoryId = drill.drillCategoryId', 
          'joinType'=>'LEFT' 
         ), 
         array('tableName'=>'drillPackage', 
          'joinCondition'=>'drillCategoryMaster.drillPackageId=drillPackage.drillPackageId', 
          'joinType'=>'LEFT' 
         ), 
         array('tableName'=>'drillMainCategory', 
          'joinCondition'=>'drillMainCategory.mainCategoryId=drillPackage.mainCategoryId', 
          'joinType'=>'LEFT' 
         ), 
      ); 
      $where=array('drillMainCategory.mainCategoryId'=>$_POST['mainCat'],'createdByUserId'=>$this->session->userdata('userId')); 
      $data=$this->commonmodel->getData($alias,$table,$where,$joinArgument); 

************用於模型的代碼*************

函數的getData($別名= '*',$表,$其中= '',$連接= '',$排序依據= '',$ whereOr = '',$ GROUPBY = '',$限制= '') {

$this->db->select($alias); 
    $this->db->from($table); 
    if($join!='') 
    { 
     for($i=0;$i<count($join);$i++) 
     { 
      $this->db->join($join[$i]['tableName'],$join[$i]['joinCondition'],$join[$i]['joinType']); 
     } 
    } 

    if($where!='') 
    { 
     foreach($where as $coulmn=>$value){ 
      $this->db->where($coulmn,$value); 
     } 
    } 

    if($whereOr!='') 
    { 
     //print_r($whereOr); 
     foreach($whereOr as $coulmn=>$value){ 
      $this->db->or_where($coulmn,$value); 
     } 
    } 

    if($orderBy!='') 
    { 
     $orderByKey=array_keys($orderBy); 
     $orderByMode=array_values($orderBy); 
     $this->db->order_by($orderByKey[0],$orderByMode[0]); 
    } 

    if($groupby != '') 
    { 
     $this->db->group_by($groupby); 
    } 

if($limit!='') 
    { 
     $limit=explode(',', $limit); 
     if(count($limit)>=2) 
     { 
      $this->db->limit($limit[1],$limit[0]); 
     }else { 
      $this->db->limit($limit); 
     } 
    } 

    $query=$this->db->get(); 
    $result=$query->result(); 
    //echo $this->db->last_query(). "<br>"; 
    return $result; 
} 

visit to know more

相關問題