title: codeigniter delete column from database
body: <p>Have two tables test and languages, I need to delete <code>title_$lang</code> column from test table when code column is deleted from language table. The tables are not connected with foreign key. It works with insert function. Here is my script:</p>
  
  <p>model:</p>
  
  <pre><code>public function deleteField($table, $id, $code){
  
               $this-&gt;dbforge-&gt;drop_column();
              if ($this-&gt;db-&gt;delete($table, array('id' =&gt; $id))&amp;&amp; $this-&gt;dbforge-&gt;drop_column('tests', "title_".$code)) {
              $this-&gt;session-&gt;set_flashdata('success', true);
          } else {
              $this-&gt;session-&gt;set_flashdata('error', true);
          }
          return isset($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : 'backend/tests';
          return isset($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : 'backend/languages';
  
          }
  </code></pre>
  
  <p>controller:</p>
  
  <pre><code>public function removefield($table = 0, $code)
      {
          if (!$table) die('!');
          $id = $this-&gt;input-&gt;get('id');
          redirect($this-&gt;admin_model-&gt;deleteField($table, $id, $code));
          echo $code;
      }
  </code></pre>
  
  <p>view:</p>
  
  <pre><code>&lt;a href="&lt;?php echo base_url();?&gt;backend/removefield/languages/?id=&lt;?php echo $row['id'];?&gt;" class="btn btn-sm btn-danger"&gt;Delete&lt;/a&gt;
  </code></pre>
  
  <p>It gives the <strong>followint errors:</strong> </p>
  
  <blockquote>
    <p>Missing argument 2 for Backend::removefield() Filename:controllers/Backend.php </p>
    
    <p>Undefined variable: code Filename: controllers/Backend.php </p>
    
    <p>Undefined property: Backend::$dbforge Filename: core/Model.php </p>
    
    <p>Call to a member function drop_column() on null Filename: models/Admin_model.php</p>
  </blockquote>