3

私はcodeigniterの基本を学び、今ではモジュールを学びました。

私の問題: modulesフォルダー内に2つのフォルダーを作成first_modulesecond_moduleました。

コントローラのfirst_module内部で私のコード:

<?php
    class First_module extends MX_Controller {
    public function index()
    {
        $this->load->view('first_module_view');            
    }
}
?>

first_module_viewページコード:

<html>
<body>
    <h1> hey this is first module </h1>
    <?php 
        echo Modules::run('second_module/second_module');
    ?>
</body>
</html>

second_moduleコントローラーページ:

<?php
class Second_module extends MX_Controller {
    public function index()
    {
        $this->load->view('second_module_view');
    }
}
?>

second_module_viewページ:

<html>
<body>
    <h1> hey this is second module </h1>
</body>
</html>

first_modulesecond_moduleのコントローラーを使用して、ビューで2番目のモジュールビューを部分的に表示しようとしていますが、機能していません。
個々に両方のコードは正常に機能していますが、Modules::run()機能していないようです。

私は何かが足りないのですか?

4

1 に答える 1

1

あなたが解決策を見つけたことは承知していますが、これはあなたが尋ねた正確な質問には答えていませんが、通常は次のようにします。

       <?php
            class First_module extends MX_Controller {
            public function index()
            {
                 $content = array();

                //send content array to 2nd view and return everything as a string to be added as content to the first view

               $content["second_view"] = $this->load->view('second_module_view',$content,true);

               $this->load->view('first_module_view',$content);            
            }
        }
        ?>

最初のモジュール ビューは次のようになります。

<html>
<body>
    <h1> hey this is first module </h1>
    <?php 
        echo $second_view;
    ?>
</body>

特にモジュールを扱ったことはありませんが、これはコントローラーとビューで行う方法です。ビュー内からのモデルとモジュールへの呼び出しを制限するためにできることをします。モデルからコントローラーで生成された変数を渡すだけです。

于 2012-08-24T13:11:29.240 に答える