2013-03-04 106 views
0

IN codeigniter我反复使用控制器来加载我的页面的所有模板.... 我已将页面划分为标题,顶部导航,左侧导航以及内容和页脚。在codeigniter中使用ajax的页面导航

这是我目前

public function get_started() { 
    if (test_login()) { 
     $this->load->view('includes/header'); 
     $this->load->view('includes/topnav'); 
     $this->load->view('includes/leftbar'); 
     $this->load->view('login_nav/get_started'); 
     $this->load->view('includes/footer'); 
    } else { 
     $this->load->view('errors/needlogin');  
    } 
} 

做是否有笨任何jQuery的AJAX佣工或插件,它可以让我保持页眉页脚和topnavigation静,让我加载使用AJAX的具体意见。

在此先感谢..

+0

你正在加载页眉页脚左等等,然后你想做什么?你想通过ajax加载特定的部分?像页脚头等?请正确澄清你的问题 – 2013-03-04 04:14:54

+0

如果你使用ajax的原因是因为模板,你可能想看看这个线程http://stackoverflow.com/questions/3957000/what-c​​odeigniter-template-library-is-best – 2013-03-04 05:06:00

+0

谢谢对于响应...但我试图使用简单的jquery .ajax()方法进行页面导航...我不知道如何在MVC中使用它。 – user1978166 2013-03-04 05:38:39

回答

0

您可以使用构造函数来设置静态标题:

//in your controller 

public $data; 

function __construct() 
{ 
    $this->data['header'] = 'static_header'; 
    $this->data['static_footer'] = 'static_footer'; 
} 

function get_started(){ 
    if (test_login()) { 
     $this->data['subview'] = 'login_nav/get_started'; 
    } else { 
     $this->data['subview'] = 'errors/needlogin'; 
    } 
     $this->load->view('template',$this->data); 
} 

function get_page(){ 
    $view = $this->load->view('your_dynamic_view','',TRUE); 
    print json_encode(array('success' => TRUE, 'view' => $view); 
} 

// in your template.php 
<div id="header"><?php echo $this->load->view('header');?></div> 
<div id="subview"><?php echo $this->load->view('subview');?></div> 
<div id="footer"><?php echo $this->load->view('footer');?></div> 

// in your script - used to load dynamic view on you subview div 
<script type="text/javascript"> 
    $.get('controller/get_page',{},function(data){ 
     if(data.success){ 
      $('#subview').html(data.view); 
     } 
    },'json') 
</script> 

消息我,如果有我的代码有问题 快乐编码--->:d