Skip to content

Instantly share code, notes, and snippets.

View cebe's full-sized avatar
☁️
working on cebe.cloud

Carsten Brandt cebe

☁️
working on cebe.cloud
View GitHub Profile
@cebe
cebe / cubrid.php
Created September 6, 2013 09:14
CUBRID PDO quote unexpected result
<?php
$pdo = new PDO('cubrid:dbname=demodb;host=localhost;port=33000', 'dba', '');
$test = 'mystring';
echo $pdo->quote($test) . "\n";
$test = "my'string";
echo $pdo->quote($test) . "\n";
@cebe
cebe / A.php
Last active April 13, 2019 06:26
PHP autoload function return values do not make any sense!
<?php class A {}
@cebe
cebe / Example.php
Created July 17, 2013 22:09
Yii ActiveRecord Unique validator example
<?php
class Example extends CActiveRecord
{
// ...
public function rules()
{
return array(
@cebe
cebe / json.php
Created June 14, 2013 22:24
This is how json_encode() treats arrays...
<?php
$a = new StdClass();
$a->prop = 2;
$a->str = "hallo";
$a->arr = array(1,2,3);
echo json_encode($a); // {"prop":2,"str":"hallo","arr":[1,2,3]}
echo json_encode((array)$a); // {"prop":2,"str":"hallo","arr":[1,2,3]}
echo json_encode(array(1,2,3)); // [1,2,3]
@cebe
cebe / ar.php
Created June 7, 2013 06:54
Getting all rows of Yii AR
<?php
// loads an array of MyModel instances
$records = MyModel::model()->findAll();
foreach($records as $record) {
// $record represents one row in the database
print_r($record->attributes); // attributes are the columns/values
}
@cebe
cebe / main.php
Last active June 21, 2019 09:25
REST routing with Yii 2 UrlManager
<?php
return array(
/* ... */
'components' => array(
/* ... */
'urlManager' => array(
'enablePrettyUrl' => true,
'rules' => require(__DIR__ . '/routes.php'),
),
@cebe
cebe / BaseRESTAction.php
Created May 18, 2013 11:18
REST Action classes for Yii 1.1
<?php
/**
* @todo: add documentation!
*
* @property string|array $returnUrl
*/
abstract class BaseRESTAction extends CAction
{
const HTML = 'html';
@cebe
cebe / classes.php
Last active December 17, 2015 10:29
Yii app controller events
<?php
class Controller extends CController
{
public function beforeAction($action)
{
// register handler for the event
$this->attachEventHandler('onUserRegister', array(Yii::app()->myComponent, 'sendEMail'));
return parent::beforeAction($action);
@cebe
cebe / view.php
Last active December 17, 2015 02:28
CGridView related objects column.
<?php
// assuming we have a User model that has a relation to Profile model named 'profile'
/** @var User $user The user model */
$this->widget('zii.widgets.grid.CGridView', array(
'id'=>'user-grid',
'dataProvider'=>$user->search(),
'filter'=>$user,
@cebe
cebe / ActiveRecordFilterBehavior.php
Created February 22, 2013 17:54
Allows to filter attributes before validation: trim,escape,re-format etc...
<?php
/**
* Allows to filter attributes before validation: trim,escape,re-format etc...
*
* List of implemented filters:
* - trim
*
* How to use:
*