获取错误调用未定义的方法Yii :: import() 当我试图访问我的Yii控制器操作时,我收到此错误 指导我访问谁以及我现在在哪里出错 我的代码是
<?php
namespace app\controllers;
use Yii;
use yii\filters\AccessControl;
use yii\web\Controller;
use yii\filters\VerbFilter;
use app\models\LoginForm;
use app\models\ContactForm;
use app\controllers\SSPController;
class BrandController extends Controller
{
public function actionIndex()
{
Yii::import('application.controllers.admin.SSPController');
SSPController::getdata();
}
}
我的SSPController类代码就像我想要调用方法getdata()
<?php
namespace app\controllers;
use Yii;
use yii\filters\AccessControl;
use yii\web\Controller;
use yii\filters\VerbFilter;
use app\models\LoginForm;
use app\models\ContactForm;
class SSPController extends Controller
{
static function getdata(){
$primaryKey = 'user_id';
$table = 'gc_od_chat';
$columns_names=$arrayName = array("user_email","user_username");
$columns = array(
array( 'db' => 'columns_names[0]', 'dt' => 'columns_names[0]', 'field' => 'columns_names[0]' ),
array( 'db' => 'columns_names[1]', 'dt' => 'columns_names[1]', 'field' => 'columns_names[1]' ),
);
$sql_details = array(
'user' =>"root",
'pass' => "",
'db' => "octachat",
'host' => "localhost"
);
echo json_encode(
$this->simple( $_GET, $sql_details, $table, $primaryKey, $columns, $joinQuery, $extraWhere )
);
}
}
答案 0 :(得分:1)
Yii 2中没有Yii :: import(),但有很多方法可以实现这一点。
例如:
Yii::$app->runAction('controller/action', $params);
(如果是action
方法)