1

私はアプリケーションを開発しています。そこでは、テーマをコード イグナイタのシステムから独立させたいと考えています。

これらのテーマは単なる css ファイルと画像であり、必ずしもビューではありません。codeigniters MVC で。

これらのテーマは、データベース変数によって選択されます。

どうすればこれを行うことができますか?

4

1 に答える 1

2

ユーザーセッションで使用されたテーマの名前を保存します。次に、各コントローラーコンストラクターで値の存在を確認し、データベースでテーマ名の存在を確認し、データをビューに渡します。ビューは、含まれているヘッダーを介して物事を処理します。

データベースは次のようになります。

theme_id | theme_name | theme_css 
------------------------------------
1        | default    | default.css
2        | fancy      | fancy.css

ビューにはすべて、次のようなものが含まれます。

<?php include header.php ?>

header.php には以下が含まれます。

<link href="/css/<?=$theme_data->css?>" rel="stylesheet" type="text/css" />

そして、標準コントローラを拡張するベース コントローラは次のようになります。

<?php
class Base_Controller extends Controller
{
    protected $theme = 'default';
    function __construct()
    {
        parent::Controller();
        if ($this->session->userdata('theme')
        {
            $this->theme = $this->session->userdata('theme');
        }
        $this->view->data['theme_data'] = $this->get_theme_data();

    }

    protected function get_theme_data()
    {
        // return data from database using $this->theme
    }

}
于 2009-12-10T18:21:03.973 に答える