0

私がやろうとしているのは、Code Igniter と PHP のコントローラーを使用して、ビューに 2 つのモデルを表示することです。最初のモデルは私のビューにうまく表示されたので、気にしないでください。しかし、2 番目のモデルには問題があります。ビューに表示できません。

2 番目のモデルには、JSON プラグインと HTML 解析が含まれています。Code Igniter コントローラーでテストしましたが、エラーなく正常に動作し、必要な出力 (HTML テーブル) が得られますが、モデルとして使用して別のコントローラーで呼び出す必要があります。

class Telephonelist_model extends CI_Model{
    public function telephoneNum(){
        //authentication
        $username = '****';
        $password = '****';
        $sc = new ServerClient();
        $login = "******";
        $content = $sc->getContent($login,array(),false);   


        $host = "*******";
        $content = $sc->getContent($host);
        $content = json_decode($content);

        //Prepair for parsing, select the text part
        foreach($content->parse->text as $myHtml);
        /**
         * Parsing
         */
        //create new dom object
        $dom = new DOMDocument();

        //load html source
        $html = $dom->loadHTML($myHtml);

        //discard white space
        $dom->preserveWhiteSpace = false;

        //the table by its tag name
        $table = $dom->getElementsByTagName('table');

        //get all rows from the table
            $rows = $table->item(2)->getElementsByTagName('tr');
            $tab = '<table>';
            foreach ($rows as $row)
            {
                // get each column by tag name
                $head = $row->getElementsByTagName('th');
                // echo the values
                if(isset($head->item(0)->nodeValue)){
                //echo '<th>';
                    $tab = '<tr><th>'.$tab.$head->item(0)->nodeValue.' </th>';
                }
                if(isset($head->item(1)->nodeValue)){
                //echo '<th>';
                $tab = '<th>'.$tab.$head->item(1)->nodeValue.' </th>';
                }

                if(isset($head->item(2)->nodeValue)){
                $tab = '<th>'.$tab.$head->item(2)->nodeValue.'<br /></th></tr>';
                }
                $cols = $row->getElementsByTagName('td');
                // echo the values
                if(isset($cols->item(0)->nodeValue)){
                $tab ='<tr><td>'.$tab.$cols->item(0)->nodeValue.' </td>';
                }

                if(isset($cols->item(1)->nodeValue)){
                $tab = '<td>'.$tab.$cols->item(1)->nodeValue.' </td>';
            }

                if(isset($cols->item(2)->nodeValue)){
                $tab = '<td>'.$tab.$cols->item(2)->nodeValue.' <br /></td></tr></table>';
                }
            }
            return $tab;
    }

}

コントローラ:

<?php
class Page extends CI_Controller{

    /**
     * Startmethode des Controllers
     * @param string $param1
     * @param string $param2
     */
    public function index($param1=null,$param2=null){
        $this->myCal($param1,$param2);
    }   

    protected function myCal($year=null, $month=null){
        $year = Util_helper::getParamAsInt($year);
        $month = Util_helper::getParamAsInt($month);

        $this->load->model('Mycal_model');
        $data['calendar'] = $this->Mycal_model->generate($year,$month);


        //Get the telephonenumber list
        $this->load->model('Telephonelist_model');
        $data['tab'] = $this->Telephonelist_model->telephoneNum();

        $this->load->view('home',$data);
    }

次の行を含めるまで、私のビューは正常に機能します。その後、カレンダーでさえ、私のビューには何も表示されません。

意見:

<!DOCTYPE html>
<html>
<head>
</head>

<body>
<div class="main"> 
       <div class = "table">

        <p>Telefonliste</p>
        <?php echo $tab;?>

    </div>

    <div class = "calender">

        <?php echo $calendar; ?>

    </div>

</div>
</body>
</html>
4

2 に答える 2

1

最初に両方のモデルをロードしてみてください。私はこの問題を頻繁に抱えており、常にこれを行う必要があります。

そう:

protected function myCal($year=null, $month=null){
    $this->load->model('Mycal_model');
    $this->load->model('Telephonelist_model');
    //the rest of your code

また、次の行を確認してください: foreach($content->parse->text as $myHtml);

多分それはスクリプトの実行を停止していますか?私はそのような foreach を見たことがありません。

于 2013-08-14T09:07:18.853 に答える
0

root の index.php 行 35 でこれを実行して、エラーを表示してみてください。

case 'development':
    error_reporting(E_ALL);
    ini_set('display_errors', '1');
于 2013-08-14T09:23:42.170 に答える