Skip to content

Instantly share code, notes, and snippets.

View mbischof's full-sized avatar

Marko Bischof mbischof

  • Hannover, Germany
View GitHub Profile
abstract class Awk extends CComponent
{
public $filename;
public $fieldSeparator = ';';
protected $data = array();
protected $cntRows = 0;
abstract public function rules();
@mbischof
mbischof / gist:7487193
Created November 15, 2013 16:26
Configuration-Array accessable via dot syntax
<?php
class Configuration extends \CConfiguration
{
/**
* usage: $configuration->get('contact.person.firstname');
*/
public function get($path, $default = null)
{
@mbischof
mbischof / gist:6707531
Created September 25, 2013 23:15
wordpress like shortcode
<?php
class ShortCodeWidget extends COutputProcessor
{
public $purifyOutput = false;
private $codes;
public function processOutput($output)
{
@mbischof
mbischof / install-command.php
Last active December 13, 2015 16:59
an install command
<?php
class InstallCommand extends CConsoleCommand
{
public function actionIndex()
{
$this->createDir('images.cache');
$this->createDir('images.cache.thumbnails');
$tables = Yii::app()->db->schema->getTableNames();
@mbischof
mbischof / afterFind.php
Last active December 13, 2015 16:59
CMaskedTextField, ActiveRecord::afterFind(), ActiveRecord::beforeSave()
<?php
$this->widget('CMaskedTextField', array(
'model' => $model,
'attribute' => 'birthday',
'mask' => '99.99.9999',
'htmlOptions' => array('size' => 32)
));
public function beforeSave()
@mbischof
mbischof / post-categories.php
Last active December 13, 2015 16:59
returns posts of a category via many-many-relation
<?php
//table post (id, title)
//table category (id, name)
//table post_category (postId, categoryId)
//class Post extends CActiveRecord
public function relations()
{
return array(
@mbischof
mbischof / onMissingTranslation.php
Last active October 13, 2015 13:07
onMissingTranslation
<?php
'components' => array(
'messages' => array(
'onMissingTranslation' => function ($event) {
echo sprintf('missing Translation: %s.%s.%s', $event->language, $event->category, $event->message);
exit;
}
)
)
@mbischof
mbischof / controller.php
Last active October 13, 2015 12:58
use of yii controller in legacy apps
<?php
function getController()
{
static $controller = null;
if ($controller == null) {
$tmp = Yii::app()->createController('site/index');
$controller = $tmp[0];
$controller->init();
@mbischof
mbischof / yii-db-useridentity.php
Last active October 11, 2015 21:48
Yii DB UserIdentity
<?php
class UserIdentity extends CUserIdentity
{
private $_id;
public function authenticate()
{
$username = strtolower($this->username);
$user = User::model()->find('LOWER(username) = ?', array($username));
@mbischof
mbischof / yii-drop-all-tables-from-database.php
Last active October 1, 2023 18:53
How to drop all tables from database using yii
<?php
$tables = Yii::app()->db->schema->getTableNames();
foreach ($tables as $table) {
Yii::app()->db->createCommand()->dropTable($table);
}