The variables which are used in views is to be declared in controller at the top as public variable
class ReportsController extends Controller
{
public $sec=0;
public $dd='';
......
......
}
The controls defined in view(from inwrep we are rendering the getrep method ) inwrep.php as follows
<?php echo CHtml::beginForm(); ?>
<?php
echo "<font size=3><b>Select SECTION:";
$models = Sections::model()->findAll();
$sec=0;
$list = CHtml::listData($models,'sec_code','sec_name');
echo CHtml::dropDownList('sec','sec',$list,array('prompt'=>'Select SECTION','empty' => 'ALL SECTIONS'));
echo "</b></font>";
<?php
/* This is the date control to use this we should have "CJuiDateTimePicker" extension. Download the extension, extract it to the our_app_folder/protected/extensions folder. Copy the entire folder not contents */
Yii::import('application.extensions.CJuiDateTimePicker.CJuiDateTimePicker');
echo "<font size=3><b>Select DATE: </b></font>";
$this->widget('CJuiDateTimePicker',array(
'name'=>'repdt',
'value'=>date('d-m-Y'), // defined the date format
'language'=>'',
'options'=>array(
'showAnim'=>'slide', //'slide','fold','slideDown','fadeIn','blind','bounce','clip','drop'
// 'showAnim'=>'slideDown',
'showHour'=>false,
'showMinute'=>false,
'showTime'=>false,
'changeMonth'=>true,
'changeYear'=>true,
'dateFormat'=>'dd-mm-yy',
'timeFormat'=>'',
'showButtonPanel'=>true,
),
'htmlOptions'=>array(
'style'=>'height:20px;'
),
));
?>
echo CHtml::button('GO',array('submit' => array('reports/getrep'))); // Invoking the 'getrep' in the controller
?>
<?php echo CHtml::endForm(); ?>
Sections is the model, from the model we are getting the sec_code as value and sec_name as name for the dropdown
And now in the getrep method of the controller we are getting the values of the controls. After collecting the values we are rendering the view getrep as follows
we can directly access the control in controller using the method $_POST method:
public function actionGetrep()
{
if($_POST['sec']!==null)
$this->sec = $_POST['sec'];
if($_POST['repdt']!==null)
$this->dd = $_POST['repdt'];
$this->render('getrep');
}
in the getrep.php (the view file)
<?php
$sec=$this->sec; // getting the sec Code
$rdate=$this->dd; // getting the date the dateformat is defined in the control itself
$username="fms";
$password="fms";
$database="fms";
mysql_connect('localhost',$username,$password);
@mysql_select_db($database) or die( "Unable to select database");
if($sec == null){
$query="SELECT * from sections"; // I am taking a example
}
else
{
$query="SELECT * from sections where sec_code=$sec and date_format(reg_date,'%d-%m-%Y')='$rdate' order by ss.sub_section"; // changing the date format in the comparision
}
$result=mysql_query($query);
$num=mysql_numrows($result);
echo "<center>";
echo "<font color='#800000' ><h1> Hyderabad Collectorate </h1></font>";
echo "<h3> DATE:$rdate </h3>"; // Displaying Date
echo "<table border='1' class=report cellspacing=0 rules=all>";
echo "<tr bgcolor='#FFE5B4'>"; // Table heading row
echo "<td><center><b>Sl.No.</b></center></td>";
echo "<td><center><b>SecCode.</b></center></td>";
echo "<td><center><b>Section</b></center></td>";
echo "<td><center><b>date</b></center></td>";
echo "</tr>";
$i=0;
$sl=1;
while($i < $num){
//$t1=mysql_result($result,$i,"id"); /* accessing fields in table */
$t1=mysql_result($result,$i,"sec_code");
$t2=mysql_result($result,$i,"section");
$t3=mysql_result($result,$i,"sdate");
/////////////////////////////////////////////////////
if($sl%2==0) /* for alternate colors in the table */
echo "<tr bgcolor=#FDEEF4>";
else
echo "<tr bgcolor=#FFF5EE>";
echo "<td align=center><center>$sl</center></td>"; // serial number
echo "<td align=center><center>$t1<br> / $t2</center></td>"; // need in format sec_code/section
echo "<td align=center><center>$t3</center></td>";
echo "<td align=center></td>";
echo "</tr>";
$i++;
$sl++;
}
echo "</table>";
echo "</center>";
?>
class ReportsController extends Controller
{
public $sec=0;
public $dd='';
......
......
}
The controls defined in view(from inwrep we are rendering the getrep method ) inwrep.php as follows
<?php echo CHtml::beginForm(); ?>
<?php
echo "<font size=3><b>Select SECTION:";
$models = Sections::model()->findAll();
$sec=0;
$list = CHtml::listData($models,'sec_code','sec_name');
echo CHtml::dropDownList('sec','sec',$list,array('prompt'=>'Select SECTION','empty' => 'ALL SECTIONS'));
echo "</b></font>";
<?php
/* This is the date control to use this we should have "CJuiDateTimePicker" extension. Download the extension, extract it to the our_app_folder/protected/extensions folder. Copy the entire folder not contents */
Yii::import('application.extensions.CJuiDateTimePicker.CJuiDateTimePicker');
echo "<font size=3><b>Select DATE: </b></font>";
$this->widget('CJuiDateTimePicker',array(
'name'=>'repdt',
'value'=>date('d-m-Y'), // defined the date format
'language'=>'',
'options'=>array(
'showAnim'=>'slide', //'slide','fold','slideDown','fadeIn','blind','bounce','clip','drop'
// 'showAnim'=>'slideDown',
'showHour'=>false,
'showMinute'=>false,
'showTime'=>false,
'changeMonth'=>true,
'changeYear'=>true,
'dateFormat'=>'dd-mm-yy',
'timeFormat'=>'',
'showButtonPanel'=>true,
),
'htmlOptions'=>array(
'style'=>'height:20px;'
),
));
?>
echo CHtml::button('GO',array('submit' => array('reports/getrep'))); // Invoking the 'getrep' in the controller
?>
<?php echo CHtml::endForm(); ?>
Sections is the model, from the model we are getting the sec_code as value and sec_name as name for the dropdown
And now in the getrep method of the controller we are getting the values of the controls. After collecting the values we are rendering the view getrep as follows
we can directly access the control in controller using the method $_POST method:
public function actionGetrep()
{
if($_POST['sec']!==null)
$this->sec = $_POST['sec'];
if($_POST['repdt']!==null)
$this->dd = $_POST['repdt'];
$this->render('getrep');
}
in the getrep.php (the view file)
<?php
$sec=$this->sec; // getting the sec Code
$rdate=$this->dd; // getting the date the dateformat is defined in the control itself
$username="fms";
$password="fms";
$database="fms";
mysql_connect('localhost',$username,$password);
@mysql_select_db($database) or die( "Unable to select database");
if($sec == null){
$query="SELECT * from sections"; // I am taking a example
}
else
{
$query="SELECT * from sections where sec_code=$sec and date_format(reg_date,'%d-%m-%Y')='$rdate' order by ss.sub_section"; // changing the date format in the comparision
}
$result=mysql_query($query);
$num=mysql_numrows($result);
echo "<center>";
echo "<font color='#800000' ><h1> Hyderabad Collectorate </h1></font>";
echo "<h3> DATE:$rdate </h3>"; // Displaying Date
echo "<table border='1' class=report cellspacing=0 rules=all>";
echo "<tr bgcolor='#FFE5B4'>"; // Table heading row
echo "<td><center><b>Sl.No.</b></center></td>";
echo "<td><center><b>SecCode.</b></center></td>";
echo "<td><center><b>Section</b></center></td>";
echo "<td><center><b>date</b></center></td>";
echo "</tr>";
$i=0;
$sl=1;
while($i < $num){
//$t1=mysql_result($result,$i,"id"); /* accessing fields in table */
$t1=mysql_result($result,$i,"sec_code");
$t2=mysql_result($result,$i,"section");
$t3=mysql_result($result,$i,"sdate");
/////////////////////////////////////////////////////
if($sl%2==0) /* for alternate colors in the table */
echo "<tr bgcolor=#FDEEF4>";
else
echo "<tr bgcolor=#FFF5EE>";
echo "<td align=center><center>$sl</center></td>"; // serial number
echo "<td align=center><center>$t1<br> / $t2</center></td>"; // need in format sec_code/section
echo "<td align=center><center>$t3</center></td>";
echo "<td align=center></td>";
echo "</tr>";
$i++;
$sl++;
}
echo "</table>";
echo "</center>";
?>
No comments:
Post a Comment