In Craft 2 you could creat a query with:
craft()->db->createCommand()->select()
.... etc.
But in Craft 3 there is no select()
Method in Craft::$app->db->createCommand()
.
Am I overlooking something?
Craft CMS Stack Exchange is a question and answer site for administrators, end users, developers and designers for Craft CMS. It only takes a minute to sign up.
Sign up to join this communityYou can use either an activeRecord for it
$customer = Customer::find()
->where(['id' => 123])
->one();
Or a query
$rows = (new \craft\db\Query())
->select(['id', 'email'])
->from('user')
->where(['last_name' => 'Smith'])
->limit(10)
->all();
Variable
you can just return it. If you call it via controller request you can render it return $this->renderTemplate('path/to/template' ['data' => $rows])
if it is an ajax request you need to encode it to json within your Controller return $this->asJson(['data' => $rows]);
It's hard to tell without further information
Aug 27, 2018 at 20:09