我是php的初学者。 这是功能:
public function actionGetreport() {
$date=$_POST['daterange'];
$daterange=explode("to",$date);
$name=$_POST['name'];
//print_r($name);die();
$connection = Yii::$app->getDb();
$command = $connection->createCommand($name)->where(
['between', 'InsertedDate', $daterange[0], $daterange[1]]
);
//filter||and
$Result = $command->queryall();
print_r($Result);die();
}
在这里,$name
有选择查询,我想使用该查询来获取日期范围之间的信息。
我得到的错误如下:
Exception 'yii\base\UnknownMethodException' with message 'Calling unknown method: yii\db\Command::where()' in D:\xampp\htdocs\oms\vendor\yiisoft\yii2\base\Component.php:294 Stack trace: #0 D:\xampp\htdocs\oms\backend\modules\report\controllers\ReportController.php(31): yii\base\Component->__call('where', Array) #1 [internal function]: backend\modules\report\controllers\ReportController->actionGetreport() #2 D:\xampp\htdocs\oms\vendor\yiisoft\yii2\base\InlineAction.php(57): call_user_func_array(Array, Array) #3 D:\xampp\htdocs\oms\vendor\yiisoft\yii2\base\Controller.php(157): yii\base\InlineAction->runWithParams(Array) #4 D:\xampp\htdocs\oms\vendor\yiisoft\yii2\base\Module.php(528): yii\base\Controller->runAction('getreport', Array) #5 D:\xampp\htdocs\oms\vendor\yiisoft\yii2\web\Application.php(103): yii\base\Module->runAction('report/report/g...', Array) #6 D:\xampp\htdocs\oms\vendor\yiisoft\yii2\base\Application.php(386): yii\web\Application->handleRequest(Object(yii\web\Request)) #7 D:\xampp\htdocs\oms\index.php(17): yii\base\Application->run() #8 {main}
答案 0 :(得分:0)
您可以使用以下简单命令
将以下代码添加到控制器操作
$date = $_POST['daterange'];
$daterange = explode("to",$date);
$name = $_POST['name'];
$data = (new \yii\db\Query())
->select($name)
->from('YOUR_TABLE_NAME')
->where(['>', start_date', $daterange[0] ])
->where(['<', start_date', $daterange[1] ])
->all();
print_r($data)