のCodeIgniterでサイトをテンプレート化の最も基本的な方法の一つは、動的に別のビューファイルをロードするテンプレートまたは「レイアウト」のphpファイルを作成することであるFIXED
<?php if (! defined('BASEPATH')) exit('No direct script access allowed');
class Welcome extends CI_Controller {
/**
* Index Page for this controller.
*
* Maps to the following URL
* http://example.com/index.php/welcome
* - or -
* http://example.com/index.php/welcome/index
* - or -
* Since this controller is set as the default controller in
* config/routes.php, it's displayed at http://example.com/
*
* So any other public methods not prefixed with an underscore will
* map to /index.php/welcome/<method_name>
* @see http://codeigniter.com/user_guide/general/urls.html
*/
public function __construct()
{
parent::__construct();
$this->load->helper('url');
$this->load->library('tank_auth');
}
public function index()
{
// Set up the template.
$this->template->set_layout('default')->enable_parser(false);
if (!$this->tank_auth->is_logged_in()) {
redirect('/auth/login/');
} else {
$data['user_id'] = $this->tank_auth->get_user_id();
$data['username'] = $this->tank_auth->get_username();
$this->load->view('welcome', $data);
}
}
}
/* End of file welcome.php */
/* Location: ./application/controllers/welcome.php */
。
このような何かを試してみて、それがあなたのために働くかどうかを確認:
ビュー/のlayout.php
<html><body>
<?php $this->load->view('header.php'); ?>
<?php $this->load->view($component); ?>
<?php $this->load->view('footer.php'); ?>
</body></html>
ビュー/ header.phpの
<h1>Header</h1>
景色/footer.php
<h6>Footer</h6>
ビュー/ login.php
<p>Login here!</p>
コントローラ/ welcome.php
public function index() {
$data['component'] = "login";
$this->load->view("layout", $data);
}
私はあなたを助けるのが大好きだが、私は自分自身であろうものにはよく分かりません**正しい**方法とみなされます。購入したテンプレートを編集し、必要に応じてより意味のあるものになるようにHTMLとCSSを変更するべきでしょう。とにかく、この質問はCIやPHPには関係しません。それは純粋なHTML/CSSのセマンティクスの質問です。あなたのタグを変更する必要があります、そして、おそらくそれらのタグに続く誰かがあなたをもっと助けることができるでしょう... –
私はまだこのテンプレートライブラリを使用したいので、私はまだ持っていると思います。少なくとも私はこれが私が必要としていると信じています。 http://getsparks.org/packages/template/show –
私は私のことをお詫びします。私はコントローラがロードされたときに私のデフォルトのレイアウトを表示する方法を理解しようとしています。私のコードは編集上です。 –