Tutorial by Examples

Accepts a mathematical expression and returns a numerical value. It is especially useful when working with different types of units (e.g. subtracting a px value from a percentage) to calculate the value of an attribute. +, -, /, and * operators can all be used, and parentheses can be added to spec...
Returns the value of an attribute of the selected element. Below is a blockquote element which contains a character inside a data-* attribute which CSS can use (e.g. inside the ::before and ::after pseudo-element) using this function. <blockquote data-mark='"'></blockquote> I...
Find single record based on id. $model = User::findOne($id); Select single column based on id. $model = User::findOne($id)->name; Retrieve the single record from the database based on condition. $model = User::find()->one(); // give first record $model = User::find()->where(['i...
Using scenario you can perform validation on different situation Define scenario in model class class User extends \yii\db\ActiveRecord { public static function tableName() { return 'user_master'; } // define validation in rule() function public ...
Vector based graphics are represented by a plethora of data that must be computed by the CPU (vector points, arcs, colors, etc). Anything other than simple shapes with minimal points and straight lines will consume vast amounts of CPU resource. There is a "Cache as Bitmap" flag that can b...
Rendering text consumes a lot of CPU. Fonts are rendered in a fashion similar to vector graphics and contain many vector points for every character. Altering text frame-by-frame will degrade performance. The "Cache as bitmap" flag is extremely useful if used correctly, meaning you must avo...
Using the Vector.<T> type and the for each loop is more performant than a conventional array and for loop: Good: var list:Vector.<Sprite> = new <Sprite>[]; for each(var sprite:Sprite in list) { sprite.x += 1; } Bad: var list:Array = []; for (var i:int = 0; i < ...
If you do not require an array to be in any particular order, a little trick with pop() will afford you enormous performance gains compared to splice(). When you splice() an array, the index of subsequent elements in that array needs to be reduced by 1. This process can consume a large chunk of tim...
If you have a value that you use often, you can store it in a variable. You could use this to define color schemes, for example. You would only have to define your scheme once and then you could use it throughout your stylesheets. To define a variable, you must prefix its name with the $ symbol. (L...
Steps to Create component: Create a folder named components in your project root folder Create your component inside components folder e.g.: MyComponent.php namespace app\components; use Yii; use yii\base\Component; use yii\base\InvalidConfigException; class MyComponent ...
Create function in MyComponent.php namespace app\components; use Yii; use yii\base\Component; use yii\base\InvalidConfigException; use yii\helpers\Url; use yii\helpers\ArrayHelper; use app\models\User; class MyComponent extends Component ...
A session is usually obtained using sessionmaker, which creates a Session class unique to your application. Most commonly, the Session class is bound to an engine, allowing instances to use the engine implicitly. from sqlalchemy.orm import sessionmaker # Initial configuration arguments Session ...
New or detached objects may be added to the session using add(): session.add(obj) A sequence of objects may be added using add_all(): session.add_all([obj1, obj2, obj3]) An INSERT will be emitted to the database during the next flush, which happens automatically. Changes are persisted when t...
To delete persisted objects use delete(): session.delete(obj) Actual deletion from the database will happen on next flush.
There are many ways find the location of a value in an array. The following example snippets all assume that the array is one of the following: String[] strings = new String[] { "A", "B", "C" }; int[] ints = new int[] { 1, 2, 3, 4 }; In addition, each one sets...
Using ActiveCell or ActiveSheet can be source of mistakes if (for any reason) the code is executed in the wrong place. ActiveCell.Value = "Hello" 'will place "Hello" in the cell that is currently selected Cells(1, 1).Value = "Hello" 'will always place "Hello&...
Implementing the IEnumerable interface allows classes to be enumerated in the same way as BCL collections. This requires extending the Enumerator class which tracks the state of the enumeration. Other than iterating over a standard collection, examples include: Using ranges of numbers based on a...
Uploading Files Uploading files in Yii is usually done with the help of [[yii\web\UploadedFile]] which encapsulates each uploaded file as an UploadedFile object. Combined with [[yii\widgets\ActiveForm]] and models, you can easily implement a secure file uploading mechanism. Creating Models Lik...
So you've uploaded your files to a folder say /backend/web/uploads/ and you want these uploads to be visible on the frontend too. The easiest option is to create a symlink in the frontend that links to the backend: ln -s /path/to/backend/web/uploads/ /path/to/frontend/web/uploads In your views y...
The <algorithm> header provides a number of useful functions for working with sorted vectors. An important prerequisite for working with sorted vectors is that the stored values are comparable with <. An unsorted vector can be sorted by using the function std::sort(): std::vector<int&...

Page 273 of 1336