title: Creating a html table dynamically based on Yii (relations)database table?
body: <p>I am trying to create "view" or a function that will build a HTML table by being given the columns in the table and the table data itself. This will be a page called by the renderPartial method in Yii.
  I imagined doing it something like this (will demonstrate using pseudo-code):</p>
  
  <pre><code>    void view(array $cols, array $tabledata) 
      {
      //$tabledata will be an array of CActiveRecord objects. $cols is an array of strings from getColumnNames().
      &lt;table&gt;&lt;thead&gt;&lt;tr&gt;
      foreach($cols as $col)
      {
          &lt;th&gt;$col&lt;/th&gt;
      }
      &lt;/tr&gt;&lt;/thead&gt;&lt;tbody&gt;
      foreach($tabledata as $data)
      {
          &lt;tr&gt;
          foreach($cols as $col)
          {
              &lt;td&gt;$data-&gt;$col&lt;/td&gt;
          }
          &lt;/tr&gt;
      }
      &lt;/tbody&gt;&lt;/table&gt;
      }
  </code></pre>
  
  <p>However the issue I am running into is I cannot get an the columns for a relation. I found <a href="http://www.yiiframework.com/doc/api/1.1/CDbTableSchema" rel="nofollow">http://www.yiiframework.com/doc/api/1.1/CDbTableSchema</a> but that seems to only give you the column names for a specific table. I need a way to get all the columns used when a relation will be used to generate the HTML table. Alternatively if someone has a better way of doing this let me know. Thanks!</p>
  
  <p>Edit: As a note, the reason I am not using CGridView including the one I listed below, is that I don't want to have to know what the columns are or the data. I want to be able to build the table using just code.</p>