app/Controller/Actionscontroller.php
<?php
App::uses('AppController', 'Controller');
class ActionsController extends AppController {
public Function index(){
App::import('Model', 'ConnectionManager');
$con = new ConnectionManager;
$cn = $con->getDataSource('default');
$tablequery="SELECT TABLE_NAME
FROM INFORMATION_SCHEMA.TABLES
WHERE TABLE_TYPE = 'BASE TABLE' AND TABLE_SCHEMA='cakephp_db' AND TABLE_NAME != 'report'";
$this->set('table',$cn->query($tablequery));
}
}
?>
app/View/Actions/index.ctp
<fieldset>
<table>
<tr><th><td>OR</td></th></tr>
<tr>
<th>CHOOSE EXISTING DATA</th>
<td>
<?php echo $this->Form->create('table',array('type' => 'get'));
echo $this->Form->select('table ', $table,['empty' => 'choose one']);?>
<?php echo $this->Form->end('submit'); ?>
</td>
</tr>
</table>
</fieldset>
app/model/action.php
<?php
App::uses('AppModel', 'Model');
class Action extends AppModel {
public $validate = array(
'table'=> array(
'required' => array(
'rule'=> 'notBlank',
'message' => 'atleast select one table'
)
)
);
}
?>
I need the result in this format. a sample output i have written
<select name="field">
<option value="">(choose one)</option>
<option value="0">1</option>
<option value="1">2</option>
<option value="2">3</option>
<option value="3">4</option>
<option value="4">5</option>
</select>
But i am getting the output in this format;By running this code.Help me to solve the issue.
<select name="table " id="tableTable">
<option value="">choose one</option>
</optgroup>
<option value="TABLE_NAME">Employee</option>
<optgroup label="TABLES">
<optgroup label="1">
</optgroup>
<option value="TABLE_NAME">House_Price</option>
<optgroup label="TABLES">
</optgroup>
<optgroup label="2">
</optgroup>
<option value="TABLE_NAME">insurence</option>
<optgroup label="TABLES">
</optgroup>
<optgroup label="3">
</optgroup>
<option value="TABLE_NAME">posts</option>
<optgroup label="TABLES">
</optgroup>
<optgroup label="4">
</optgroup>
<option value="TABLE_NAME">topics</option>
<optgroup label="TABLES">
</optgroup>
<optgroup label="5">
</optgroup>
<option value="TABLE_NAME">users</option>
<optgroup label="TABLES">
</optgroup>
<optgroup label="6">
</optgroup>
<option value="TABLE_NAME">visualizations</option>
<optgroup label="TABLES">
</optgroup>
</select>