【发布时间】:2015-02-25 13:06:32
【问题描述】:
我对 Yii 完全陌生,即使看起来微不足道,我也需要帮助。我有一个页面,我从我的数据库生成一个表,我添加了一个搜索选项,我还需要将结果生成为一个表。
问题是当我点击按钮时没有任何反应。 我也尝试过使用提交,但没有成功。
这是我的代码:
...views/supermarkets/index.php:
<?php
use yii\helpers\Html;
use yii\widgets\LinkPager;
use app\views\supermarkets\search;
?>
<h1>Supermarkets</h1>
<ul>
<p>
Search by Name
</p>
<INPUT TYPE = "Text" VALUE ="" NAME = "searchname">
<button onclick="myFunction($_POST['searchname'])">Search</button>
<h3> </h3>
<?php
$array = (array) $supermarkets;
function myFunction($sname){
if (isset($sname) && $sname!='') {
$row = Yii::app()->db->createCommand(array(
'select' => '*',
'from' => 'supermarkets',
'where' => array('like', 'Name','%'.$sname.'')
))->queryRow();
$array = (array) $row;
}
echo $array;
$this->render('index',array('supermarkets' => $array));
}
function build_table($array){
// start table
$html = '<table class="altrowstable" id="alternatecolor">';
// header row
$html .= '<tr>';
foreach($array[0] as $key=>$value){
$html .= '<th>' . $key . '</th>';
}
$html .= '</tr>';
// data rows
foreach( $array as $key=>$value){
$html .= '<tr>';
foreach($value as $key2=>$value2){
$html .= '<td>' . $value2 . '</td>';
}
$html .= '</tr>';
}
// finish table and return it
$html .= '</table>';
return $html;
}
echo build_table($array);
?>
<?= LinkPager::widget(['pagination' => $pagination]) ?>
即使在调试中它也不会通过 myFunction。请问有什么建议吗?
【问题讨论】:
-
您是从客户端脚本(Javascript)调用服务器脚本(PHP)?这有意义吗?请阅读一些基础教程
-
很抱歉,我已经提到我对这个完全陌生,我不知道 javascript,你能告诉我怎么做吗?
标签: php model-view-controller yii onclick