$connection = Yii::$app->getDb(); $command = $connection->createCommand($sql); $command->execute();
$model = new User(); $model->name = 'John Doe'; $model->email = 'johndoe@example.com'; $model->save();
$cache = Yii::$app->cache; $data = $cache->get('data'); if ($data === false) { $data = expensiveFunction(); $cache->set('data', $data, 3600); }This code creates a caching object and checks if the variable "data" is already in the cache. If not, it runs an expensiveFunction() to generate the data and stores it in the cache for an hour. Package library: yii\caching Overall, Yii comes with many built-in libraries to help with numerous common web development tasks. The code examples above are just a few of the possibilities in Yii.