1

headerview.php

<!DOCTYPE html>
<html lang="en">
    <head>
        <meta charset="utf-8">
        <title><?php echo $title; ?></title>
    </head>
    <body>
        <div id="topmenu">
            <ul>
                <li><a href="What Should I write Here ?">Home</a></li>
                <li><a href="What Should I write Here ?">About Us</a></li>
                <li><a href="What Should I write Here ?">Contact Us</a></li>
            </ul>    
        </div>  

footerview.php

</body>
</html>

controllers / main.php

<?php if (!defined('BASEPATH')) exit('No direct script access allowed');

class main extends CI_Controller {
 function index(){
     $this->load->view('headerview');
     $this->load->view('homeview');
     $this->load->view('footerview');
  } 

}
?>

1つの関数でview/about_us_view.php、view / contact.phpなどのページを表示するにはどうすればよいですか?

-ありがとう。

4

2 に答える 2

1

私はすべてのurビューページがルートビューフォルダにあると仮定します

コントローラ

<?php if (!defined('BASEPATH')) exit('No direct script access allowed');

class Main extends CI_Controller {

 function index($page = 'homeview')
{

    if ( ! file_exists('application/views/'.$page.'.php')){

        show_404();
    }
    else{

    $this->load->view('headerview');
    $this->load->view( $page);
    $this->load->view('footerview');
        }

}

}

ヘッダ

<!DOCTYPE html>
<html lang="en">
    <head>
        <meta charset="utf-8">
        <title><?php echo $title; ?></title>
    </head>
    <body>
        <div id="topmenu">
            <ul>
                <li><a href="<?php echo base_url('index.php/main');?>">HOME</a></li>
                <li><a href="<?php echo base_url('index.php/main/index/about_us_view');?>">About Us</a></li>
                <li><?php echo base_url('index.php/main/index/contact');?>">Contact Us</a></li>
            </ul>    
        </div> 

基本的なURLパターンを以下に示します

http://example.com/[controller-class]/[controller-method]/[arguments]

インデックス関数では、引数としてページ名を渡します

連絡先ページを表示するには

<?php echo base_url('index.php/main/index/contact');?>

ここ

コントローラー:メイン

method:index

引数:連絡先

また、config/autoload.phpのURLヘルパーを自動ロードします。

$autoload['helper'] = array('url');
于 2013-02-21T12:47:16.697 に答える
-1

次のことを行う必要があります。

headerview.php

<!DOCTYPE html>
<html lang="en">
    <head>
        <meta charset="utf-8">
        <title><?php echo $title; ?></title>
    </head>
    <body>

homeview.php

<?php $this->load->view('headerview'); ?>
<div id="topmenu">
            <ul>
                <li><a href="What Should I write Here ?">Home</a></li>
                <li><a href="What Should I write Here ?">About Us</a></li>
                <li><a href="What Should I write Here ?">Contact Us</a></li>
            </ul>    
        </div>  
<?php $this->load->view('footerview'); ?>

そしてfooterview.php

</body>
</html>

そしてコントローラー

<?php if (!defined('BASEPATH')) exit('No direct script access allowed');

class main extends CI_Controller {
 function index(){
     $this->load->view('homeview');
  } 
}
?>
于 2013-02-21T12:14:35.710 に答える