2017-09-11 6 views
0

私はcodeigniterを初めて使用していますので、このコードをMVCに合うように変更する方法を知りたいのですが、現在、私はhtmlとphpコードをview.Anyに持っています。私はビューでphpとhtmlコードを分けることができますか?codeigniter mvcに基づいて以下のコードを変更するには?

My View is as follows 


<html> 
     <head> 
      <script src="https://code.jquery.com/jquery-2.1.1.min.js" type="text/javascript"></script> 
      <link href="https://cdnjs.cloudflare.com/ajax/libs/select2/4.0.1/css/select2.min.css" rel="stylesheet" /> 
      <script src="https://cdnjs.cloudflare.com/ajax/libs/select2/4.0.1/js/select2.min.js"></script> 
      <script type="text/javascript"> 
       $(document).ready(function() { 
        $(".searchabledropdown").select2(); 

      </script> 
     </head> 
     <body> 

      <form action=""> 
       <div> 
        <select id="main_language" name ="main_language"> 
         <option>English</option> 
         <option>Japanese</option> 
        </select> 
        <input type="button" value="Set Main Language"> 
       </div> 
       <div> 
        <h3>Translation Management</h3> 
       </div> 
       <div> 
         <select name="lang_choice1" id="lang_choice1"> 
          <!-- <option value="" selected="selected">-----</option>--> 
          <?php 
          $path = './application/language/'; 
          $dir = new DirectoryIterator($path); 
          foreach ($dir as $fileinfo) { 
           if ($fileinfo->isDir() && !$fileinfo->isDot()) { 
            echo "<option value='" . $fileinfo->getFilename() . "'>".$fileinfo->getFilename()."</option>"; 
           } 
          } 
          ?> 
         </select> 
        => <select name="lang_choice2"> 
         <!--<option value="" selected="selected">-----</option>--> 
         <?php 
         $path = './application/language/'; 
         $dir = new DirectoryIterator($path); 
         foreach ($dir as $fileinfo) { 
          if ($fileinfo->isDir() && !$fileinfo->isDot()) { 
           echo "<option value='" . $fileinfo->getFilename() . "'>".$fileinfo->getFilename()."</option>"; 
          } 
         } 
         ?> 
        </select> 
       </div> 

次のように私のコントローラである:

class Language extends CI_Controller 
{ 
    public function __construct() 
    { 
     parent::__construct(); 

    } 

    public function index() 
    { 
     $this->accesscontrol->can_or_redirect('view', 'translation'); 
     $this->output->view('translation/language'); 
    } 

} 

答えて

0

あなたの条件の基準に合格したすべてのファイルとの中間の配列を持っており、この配列を渡し、その後、あなたのコントローラ機能にDirectoryIteratorの関連する操作を移動する必要がありますビュー。あなたのビューでは、余分な操作なしで配列を印刷するだけです。 CIのビュー機能に利用可能な2番目の引数があり

、あなたのケースでは、それは次のようになります。

$this->output->view('translation/language', $array_with_files); 

https://www.codeigniter.com/user_guide/general/views.html

を参照してください
関連する問題