slevin10
(Slevin10)
1
hello
I try to view a page within another page.
But I can’t not do it in a simple way
only through the drop down
drop down code:(that work!)
echo CHtml::dropDownList('days','', $day, array('ajax' => array(
'type' => 'POST',
'url'=>Yii::app()->createUrl('main/CreatDayTable'),
'update'=>'#taytable',
'data'=>array('day'=>'js:this.value',),
)));?>
<div id="taytable">....
the way i want it to work direct:
<?php echo $this->renderPartial('dynamic_day_table',array('day'=>'1'));?>
the controller function is:
public function actionCreatDayTable() {
$this->renderPartial('dynamic_day_table');
}
what am i doing wrong?
georaldc
(Georaldc)
2
Any error popping up? Only reason I would see this not work is if that view file doesn’t exist inside your controller’s view folder
ahmed201
(Rifajas)
3
use this in your view
$this->renderPartial('/main/CreatDayTable', array('day'=>1));
where main refers name of the folder containing view and CreatDayTable is the name of the view you want to render
slevin10
(Slevin10)
4
georaldc and Ahamed Rifaideen
thenks for the anser but it is not work the error i’m geting in both ways is :
Undefined index: day
ahmed201
(Rifajas)
5
post your view to resolve it. is it works normally in its own controller?
slevin10
(Slevin10)
6
first view:
<?php yii::app()->clientScript->registerCoreScript('jquery');?>
<?php
$day= Yii::app()->locale->getWeekDayNames($width='narrow');
echo CHtml::dropDownList('days','', $day, array('ajax' => array(
'type' => 'POST',
'url'=>Yii::app()->createUrl('main/CreatDayTable'),
'update'=>'#taytable',
'data'=>array('day'=>'js:this.value',),
)));
?>
<div id="taytable">
<?php echo $this->renderPartial('/main/dynamic_day_table', array('day'=>1)); ?>
</div>
second view:
<h3><?php echo $theDay=1+$_POST['day'];?></h3>
<?php
$class=array('hoer','a','b','c','d','h','e');
$hour=array('','7:00','8:00','9:00','10:00','11:00','12:00','12:45','13:30','14:30','15:15','16:00','16:45');
echo "<table>";
for($su = 0; $su<12; $su++)
{
echo "<tr>";
for($am = 0; $am<7; $am++)
{
if($su==0)
{
echo "<th>" ;
echo $class[$am];
echo "</th>" ;
}
elseif ($am==0)
{
echo "<td>";
echo $hour[$su];
echo "</td>";
}else {
echo "<td class='buttonClass'>";
$timecode="$su$theDay";
echo MainController::returnDailyActivitys(array('timecode'=>$timecode,'class'=>$am)) ;
echo $timecode;
echo CHtml::button('create', array('onclick' => 'js:document.location.href="index.php?r=activity/create&time_code='.$timecode.'"'));
echo "</td>";
}
}
echo "</tr>";
}
echo "</table>";
?>
MainControler:
<?php
class MainController extends Controller
{
public function actionIndex()
{
$this->render('index');
}
public function returnDailyActivitys($param)
{
$activitys= Activity::classActivitys(array('class_code'=>$param['class']));
foreach ($activitys as $activity)
{
if($activity->timetable_code==$param['timecode'])
{
echo "<h2>" . $activity->activity_name . "</h2>";
echo "<ul>";
foreach ($activity->workerToActivities as $worker)
{
echo "<li>" . $worker->worker_nickname. "</li>";
}
echo "</ul>";
echo "<ul>";
foreach ($activity->studentToActivitys as $student)
{
echo "<li>" . $student->stu_nickname. "</li>";
}
echo "</ul>";
}
}
}
public function returnActivitys($param)
{
$activitys = Activity::model()->findAllByAttributes(array('timetable_code'=>$param));
foreach($activitys as $activity)
{
echo "<h2>" . $activity->activity_name . "</h2>";
echo "<ul>";
foreach ($activity->workerToActivities as $worker)
{
echo "<li>" . $worker->worker_nickname. "</li>";
}
echo "</ul>";
echo "<ul>";
foreach ($activity->studentToActivitys as $student)
{
echo "<li>" . $student->stu_nickname. "</li>";
}
echo "</ul>";
}
}
public function actionCreatDayTable() {
$this->renderPartial('dynamic_day_table');
}
ahmed201
(Rifajas)
7
hi slevin10 here you are passing the parameter day to your second view so in the second view you can access this param directly via
$day
so use the following in your second view
<h3><?php echo $theDay=1+$day;?></h3>
instead of
<h3><?php echo $theDay=1+$_POST['day'];?></h3>