未定义的变量:在yii视图中邀请

时间:2014-01-03 21:49:32

标签: php function variables yii

这是我的观看代码

<?php
Yii::import('common.extensions.chartjs.assets.js.*');
echo $eventdata['event_name']."<br>";
echo $contribution = Event::model()->contribution($eventdata['id'])."<br>";
echo $percentage = ($contribution/$eventdata['funding_goal_amount'])*100;
echo "<br>".Event::model()->dayleft($eventdata['id'])."<br>";
if($invites) {
$sms = 0;
$email = 0;
$totalinvites = count($invites);
foreach ($invites as $key => $data) {
    if($data['type'] == 3) {
        ++$sms;
    }
    if($data['type'] == 1) {
        ++$email;
    }
}

//gets the last 30 days
$d = array();
for($i = 0; $i < 28; $i++) 
$d[] = date("d", strtotime('-'. $i .' days'));
$data=array(
);
$con=0;
foreach ($d as $key => $value) {
    echo($value);
    echo("<br>");
    if($con==1)
    {
        die;
    }

    $data[]=callinvites($value);
}
echo(var_dump($data));
echo "Total invites are $totalinvites <br>";
echo "Invites by sms are $sms <br>";
echo "Invites by email are $email <br>";

}


echo "Google analytic api to come here <br>";
echo Event::model()->peopleContributed($eventdata['id'])."<br>";
if($contributors) {
    foreach ($contributors as $key => $data) {
        echo $data['fname']."<br>";
    }
}
?>

<script type="text/javascript" src="https://www.google.com/jsapi"></script>
    <script type="text/javascript">
          google.load("visualization", "1", {packages:["corechart"]});
          google.setOnLoadCallback(drawChart);
          function drawChart() {
        var data = google.visualization.arrayToDataTable([
          ['Year', 'Sales', 'Expenses'],
          ['2013',  1000,      400],
          ['2014',  1170,      460],
          ['2015',  660,       1120],
          ['2016',  1030,      540]
        ]);

        var options = {
          title: 'Company Performance',
          hAxis: {title: 'Year',  titleTextStyle: {color: '#333'}},
          vAxis: {title:'Sales',minValue: 0}
        };

        var chart = new      google.visualization.AreaChart(document.getElementById('chart_div'));
        chart.draw(data, options);
      }
    </script>

<div id="chart_div">

</div>
<div class="visits">
    <?php
        $this->widget('common.extensions.HZL.google.HzlVisualizationChart', array('visualization' => 'AreaChart',
        'data' => array(
            array('day', 'Hours per Day'),
            array('Work', 11),
            array('Eat', 2),
            array('Commute', 2),
            array('Watch TV', 2),
            array('Sleep', 7)
        ),
        'options' => array('title' => 'INVITES')));
    ?>
</div>

<?php
function callinvites($date)
{
    $today_date=date('d');

    $month=date('m');
    echo $month;
    $year=date('y');
    if($date>$today_date)
    {
        if($month=='01')
        {
            $month='12';
        }
        else
        {
            $month=$month-1;
        }
        if($month=='12')
        {
            $year=$year-1;
        }
    }
    $count=0;
    $count_email=0;
    $count_mobile=0;
    foreach ($invites as $key => $value) {
        $date2=new DateTime($value["created"]);
        $date1=$date2->format('d');
        $year1=$date2->format('y');
        $month1=$date2->format('m');
        if($date1==$date && $year1==$year && $month==$month1)
        {
            $count=$count + 1;
        }
        if($date1==$date && $year1==$year && $month==$month1 && $value["type"]=='1')
        {
            $count_email=$count_email+1;
        }
        if($date1==$date && $year1==$year && $month==$month1 && $value["type"]=='3')
        {
            $count_mobile=$count_mobile+1;
        }
    }
    return array($date,$count,$count_email,$count_mobile);
} 
?>

当我调用函数callinvites并说undefined variable : invites in yii view

时,我收到错误消息

虽然我用过这个

echo(var_dump($invites));

这显示了一个大小为20的数组,其中包含数据库中的值,那么为什么会发生错误?

1 个答案:

答案 0 :(得分:0)

callinvites功能中尝试更改此行

foreach ($invites as $key => $value) {

foreach ($this->invites as $key => $value) {