我是Yii的新手,我想从我的控制器传递PHP变量值来查看。有人可以帮忙吗。我被困在这里。我必须使用JavaScript在自动完成字段中计算此变量。提前谢谢。
我的控制器操作:
public function actionIndex()
{
$user = Yii::app()->db->createCommand()
->select('cust_name')
->from('mst_customers')
->queryAll();
$dataProvider=new CActiveDataProvider('model_name');
$this->render('index',array(
'dataProvider'=>$dataProvider,
));
}
我的观点:
<!--Content-->
<div id="content">
<div style="padding: 10px;">
<a href="<?php echo $this->createUrl('/controller_name/create');?>" title="Create New Host" class="btn btn-primary circle_ok" style="text-decoration: none;" >Add New Host to Customer</a>
<div style="float:right">
<?php
echo CHtml::link('Upload Customer CSV', array('/controller_name/uploadCustomers'), array(
'onclick'=>'return hs.htmlExpand(this, { objectType: "iframe", wrapperClassName: "full-size", align: "center" } )',
'class'=>'btn btn-primary',
'id'=>'upload_link',
));
?>
</div>
</div>
<h3><?php echo htmlspecialchars($title); ?></h3>
<h3><?php echo $title; ?></h3>
<div class="innerLR">
<div class="row-fluid">
<?php
$obj=$this->widget('zii.widgets.grid.CGridView', array(
'dataProvider'=>$dataProvider,
//'afterAjaxUpdate'=>'\'changeTRColor()\'',
//'itemView'=>'_view',
'columns'=>array(
array( // display 'create_time' using an expression
'name'=>'name',
'value'=>'$data->host_name',
),
array(
'name'=>'serviceId',
'value'=>'$data->host_serviceid',
),
array(
'name'=>'customer',
'value'=>'$data->customers->cust_name',
),
array(
'class'=>'CButtonColumn',
'template'=>'{delete}{update}',)
),
));
?>
</div>
<html lang="en">
<head>
<meta charset="utf-8">
<title>jQuery UI Autocomplete - Default functionality</title>
<link rel="stylesheet" href="//code.jquery.com/ui/1.10.4/themes/smoothness/jquery-ui.css">
<script src="//code.jquery.com/jquery-1.9.1.js"></script>
<script src="//code.jquery.com/ui/1.10.4/jquery-ui.js"></script>
<link rel="stylesheet" href="/resources/demos/style.css">
<script type="text/javascript">
//autocomplete
$(function() {
var availableTags =<?php echo CJSON::encode($user);?>;
/*"ActionScript",
"AppleScript",
"Asp",
"BASIC",
"C",
"C++",
"Clojure",
"COBOL",
"ColdFusion",
"Erlang",
"Fortran",
"Groovy",
"Haskell",
"Java",
"JavaScript",
"Lisp",
"Perl",
"PHP",
"Python",
"Ruby",
"Scala",
"Scheme"*/
console.log(availableTags);
$( "#Search" ).autocomplete({
source: availableTags
});
});
</script>
</head>
<body>
<div class="ui-widget">
<label for="Search">Search Customer: </label>
<input id="Search">
</div>
</body>
</html>
<div class="separator bottom"></div>
</div>
</div>
<!-- // Content END -->
<div class="clearfix"></div>
<!-- // Sidebar menu & content wrapper END -->
<div id="footer" class="hidden-print">
<?php $this->renderPartial('application.views.layouts._footer_inc'); ?>
</div>
答案 0 :(得分:1)
$this->render('index',array(
'dataProvider'=>$dataProvider,
'user' => $user,
));