This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<link rel="import" href="../paper-button/paper-button.html"> | |
<link rel="import" href="../topeka-elements/avatars.html"> | |
<link rel="import" href="../core-icon/core-icon.html"> | |
<link rel="import" href="../topeka-elements/category-images.html"> | |
<link rel="import" href="../topeka-elements/theme.html"> | |
<link rel="import" href="../topeka-elements/topeka-resources.html"> | |
<link rel="import" href="../topeka-elements/topeka-category.html"> | |
<link rel="import" href="../core-pages/core-pages.html"> | |
<polymer-element name="my-element"> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
private function relationInfo($model, $name, $related_id = false) | |
{ | |
$relation = $model->getRelation($name, false); | |
if ($relation === null) return null; | |
$info = []; | |
$info['class'] = $relation->modelClass; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
class ImageController extends \yii\rest\ActiveController | |
{ | |
public $modelClass = 'app\models\Image'; | |
public $relationAttribute = 'imageIds'; | |
public $relations = [ | |
'tags' => 'tag_id', | |
'owner' => 'owner_id' | |
]; | |
public function actionRelationships($id = '') |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
public function beforeAction($action) | |
{ | |
if ($action->id !== 'options' && $action->id !== 'ping') { | |
/** | |
* Try to auto login user if auth headers are received within request. | |
*/ | |
$authHeader = Yii::$app->request->getHeaders()->get('authorization'); | |
if ($authHeader !== null) { | |
if (preg_match('/^Bearer\s+(.*?)$/', $authHeader, $matches)) { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* use case example : | |
* | |
* Lets say we want to ask API for 50 products, with date = today and having 'abc' in their names, | |
* we only want to retrieve 'name' and 'sold' fields from db (Yii uses SQL SELECT for this), | |
* but also joined with their related shop (having shop defined as relation (see extraFields method)) | |
* | |
* Code to run inside Vue component: | |
* | |
* import { Collection } from "~/scripts/yii.js"; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const minute = 60; | |
const hour = minute * 60; | |
const day = hour * 24; | |
const week = day * 7; | |
const month = day * 30; | |
const year = day * 365; | |
/** | |
* Convert a date to a relative time string, such as | |
* "a minute ago", "in 2 hours", "yesterday", "3 months ago", etc. |