Skip to content

Instantly share code, notes, and snippets.

list($controller, $actionID) = Yii::app()->createController('site/contact');
$controller->layout = false;
$action = $controller->createAction($actionID);
ob_start();
$action->runWithParams(array('id'=>1));
$output = ob_get_contents();
ob_end_clean();
array(
'class' => 'CCheckBoxColumn',
'checked' => 'in_array($data->user_id, ' . var_export($campaign->reviewIds, 1) . ')',
'value' => '$data->user_id',
'selectableRows' => 100,
),
@yjeroen
yjeroen / gist:1633460
Created January 18, 2012 15:15
save relations pattern
# What I want:
# A method that saves related (simple!) models. Simple models only have 1 attribute that requires user input.
# Second thing is that I want relations to be toggled with an "active" attribute.
# What I have:
# If I want a Many Many relation to be 'toggled', i need to make a Has Many relation to the in-between-table Model.
# - Public array which holds all related data that needs to be saved.
# The array is like this:
array
(
class foo extends CActiveRecord
class User extends foo
class Post extends foo
userController User Post
========== === ===
{
function actionThatAddsUserAndPosts
@yjeroen
yjeroen / gist:1560242
Created January 4, 2012 14:22
I think I got the solution!
<?php
class foo extends CActiveRecord
{
public function save($runValidation=true,$attributes=null)
{
if( Yii::app()->db->getCurrentTransaction() === null )
{
$transaction = Yii::app()->db->beginTransaction();
$transaction->attachbehavior('modelSaveTransaction', new CBehavior);
## tr() is a custom trace function that does Yii::trace(CVarDumper::dumpAsString($user),'jlog');
CONTROLLER:
/**
* Creates a new model.
* If creation is successful, the browser will be redirected to the 'view' page.
*/
public function actionCreate()
{
@yjeroen
yjeroen / gist:1534731
Created December 29, 2011 16:04
dynamic column
VIEW:
$this->widget('zii.widgets.grid.CGridView', array(
'id'=>'incident-grid',
'ajaxUpdate'=>true,
'dataProvider'=>$model->search(),
'filter'=>$model,
'columns'=>$columns
));
@yjeroen
yjeroen / gist:1534181
Created December 29, 2011 13:47
E_STRICT error in gridview 2
VIEW:
$this->widget('zii.widgets.grid.CGridView', array(
'id'=>'incident-grid',
'ajaxUpdate'=>true,
'dataProvider'=>$model->search(),
'filter'=>$model,
'columns'=>$columns
));
@yjeroen
yjeroen / gist:1534128
Created December 29, 2011 13:34
E_STRICT error in gridview
I have a CGridview, with a column that calls a function in the model.
$data->getActieveKanalen($data->id, '.$kanaal->id.', $row)
Today, I turned E_STRICT on, and I got the following PHP error. Before I never saw this, because only E_ALL was on. With only E_ALL, the code works without any problems..
PHP Error
@yjeroen
yjeroen / gist:1400069
Created November 28, 2011 11:29
composite PK like uniqueness
array('field1', 'unique', 'criteria'=>array(
'condition'=>'field2=:field2',
'params'=>array(':field2'=>$this->field2),
)),