Skip to content
This repository has been archived by the owner on Nov 21, 2019. It is now read-only.

Commit

Permalink
Added withoutAdminView Gii CRUD template
Browse files Browse the repository at this point in the history
withoutAdminView CRUD template provides functionality like normal template
but produces merge of admin and index view as index
  • Loading branch information
canni committed Jan 7, 2011
1 parent 6b6e607 commit ae09aa1
Show file tree
Hide file tree
Showing 7 changed files with 416 additions and 0 deletions.
39 changes: 39 additions & 0 deletions gii/mongoCRUD/templates/withoutAdminView/_form.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<?php
/**
* The following variables are available in this template:
* - $this: the CrudCode object
*/
?>
<div class="form">

<?php echo "<?php \$form=\$this->beginWidget('CActiveForm', array(
'id'=>'".$this->class2id($this->modelClass)."-form',
'enableAjaxValidation'=>false,
)); ?>\n"; ?>

<p class="note">Fields with <span class="required">*</span> are required.</p>

<?php echo "<?php echo \$form->errorSummary(\$model); ?>\n"; ?>

<?php
foreach($this->modelObject->attributeNames() as $name)
{
if($name == '_id')
continue;
?>
<div class="row">
<?php echo "<?php echo ".$this->generateActiveLabel($this->modelClass,$name)."; ?>\n"; ?>
<?php echo "<?php echo ".$this->generateActiveField($this->modelClass,$name)."; ?>\n"; ?>
<?php echo "<?php echo \$form->error(\$model,'{$name}'); ?>\n"; ?>
</div>

<?php
}
?>
<div class="row buttons">
<?php echo "<?php echo CHtml::submitButton(\$model->isNewRecord ? 'Create' : 'Save'); ?>\n"; ?>
</div>

<?php echo "<?php \$this->endWidget(); ?>\n"; ?>

</div><!-- form -->
32 changes: 32 additions & 0 deletions gii/mongoCRUD/templates/withoutAdminView/_search.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?php
/**
* The following variables are available in this template:
* - $this: the CrudCode object
*/
?>
<div class="wide form">

<?php echo "<?php \$form=\$this->beginWidget('CActiveForm', array(
'action'=>Yii::app()->createUrl(\$this->route),
'method'=>'get',
)); ?>\n"; ?>

<?php foreach($this->modelObject->attributeNames() as $name): ?>
<?php
$field=$this->generateInputField($this->modelClass,$name);
if(strpos($field,'password')!==false)
continue;
?>
<div class="row">
<?php echo "<?php echo \$form->label(\$model,'{$name}'); ?>\n"; ?>
<?php echo "<?php echo ".$this->generateActiveField($this->modelClass,$name)."; ?>\n"; ?>
</div>

<?php endforeach; ?>
<div class="row buttons">
<?php echo "<?php echo CHtml::submitButton('Search'); ?>\n"; ?>
</div>

<?php echo "<?php \$this->endWidget(); ?>\n"; ?>

</div><!-- search-form -->
173 changes: 173 additions & 0 deletions gii/mongoCRUD/templates/withoutAdminView/controller.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,173 @@
<?php
/**
* This is the template for generating a controller class file for CRUD feature.
* The following variables are available in this template:
* - $this: the CrudCode object
*/
?>
<?php echo "<?php\n"; ?>

class <?php echo $this->controllerClass; ?> extends <?php echo $this->baseControllerClass."\n"; ?>
{
/**
* @var string the default layout for the views. Defaults to '//layouts/column2', meaning
* using two-column layout. See 'protected/views/layouts/column2.php'.
*/
public $layout='//layouts/column2';

/**
* @return array action filters
*/
public function filters()
{
return array(
'accessControl', // perform access control for CRUD operations
);
}

/**
* Specifies the access control rules.
* This method is used by the 'accessControl' filter.
* @return array access control rules
*/
public function accessRules()
{
return array(
array('allow', // allow all users to perform 'index' and 'view' actions
'actions'=>array('index','view'),
'users'=>array('*'),
),
array('allow', // allow authenticated user to perform 'create' and 'update' actions
'actions'=>array('create','update'),
'users'=>array('@'),
),
array('allow', // allow admin user to perform 'admin' and 'delete' actions
'actions'=>array('admin','delete'),
'users'=>array('admin'),
),
array('deny', // deny all users
'users'=>array('*'),
),
);
}

/**
* Displays a particular model.
* @param integer $id the ID of the model to be displayed
*/
public function actionView($id)
{
$this->render('view',array(
'model'=>$this->loadModel($id),
));
}

/**
* Creates a new model.
* If creation is successful, the browser will be redirected to the 'view' page.
*/
public function actionCreate()
{
$model=new <?php echo $this->modelClass; ?>;

// Uncomment the following line if AJAX validation is needed
// $this->performAjaxValidation($model);

if(isset($_POST['<?php echo $this->modelClass; ?>']))
{
$model->attributes=$_POST['<?php echo $this->modelClass; ?>'];
if($model->save())
$this->redirect(array('view','id'=>$model-><?php echo $this->modelObject->primaryKey(); ?>));
}

$this->render('create',array(
'model'=>$model,
));
}

/**
* Updates a particular model.
* If update is successful, the browser will be redirected to the 'view' page.
* @param integer $id the ID of the model to be updated
*/
public function actionUpdate($id)
{
$model=$this->loadModel($id);

// Uncomment the following line if AJAX validation is needed
// $this->performAjaxValidation($model);

if(isset($_POST['<?php echo $this->modelClass; ?>']))
{
$model->attributes=$_POST['<?php echo $this->modelClass; ?>'];
if($model->save())
$this->redirect(array('view','id'=>$model-><?php echo $this->modelObject->primaryKey(); ?>));
}

$this->render('update',array(
'model'=>$model,
));
}

/**
* Deletes a particular model.
* If deletion is successful, the browser will be redirected to the 'index' page.
* @param integer $id the ID of the model to be deleted
*/
public function actionDelete($id)
{
if(Yii::app()->request->isPostRequest)
{
// we only allow deletion via POST request
$this->loadModel($id)->delete();

// if AJAX request (triggered by deletion via admin grid view), we should not redirect the browser
if(!isset($_GET['ajax']))
$this->redirect(isset($_POST['returnUrl']) ? $_POST['returnUrl'] : array('index'));
}
else
throw new CHttpException(400,'Invalid request. Please do not repeat this request again.');
}

/**
* Manages all models.
*/
public function actionIndex()
{
$model = new <?php echo $this->modelClass; ?>('search');
$model->unsetAttributes();

if(isset($_GET['<?php echo $this->modelClass; ?>']))
$model->setAttributes($_GET['<?php echo $this->modelClass; ?>']);

$this->render('index', array(
'model'=>$model
));
}

/**
* Returns the data model based on the primary key given in the GET variable.
* If the data model is not found, an HTTP exception will be raised.
* @param integer the ID of the model to be loaded
*/
public function loadModel($id)
{
$model=<?php echo $this->modelClass; ?>::model()->findByPk(<?php echo ($this->modelObject->primaryKey() === '_id') ? 'new MongoId($id)' : '$id'; ?>);
if($model===null)
throw new CHttpException(404,'The requested page does not exist.');
return $model;
}

/**
* Performs the AJAX validation.
* @param CModel the model to be validated
*/
protected function performAjaxValidation($model)
{
if(isset($_POST['ajax']) && $_POST['ajax']==='<?php echo $this->class2id($this->modelClass); ?>-form')
{
echo CActiveForm::validate($model);
Yii::app()->end();
}
}
}
23 changes: 23 additions & 0 deletions gii/mongoCRUD/templates/withoutAdminView/create.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?php
/**
* The following variables are available in this template:
* - $this: the CrudCode object
*/
?>
<?php
echo "<?php\n";
$label=$this->pluralize($this->class2name($this->modelClass));
echo "\$this->breadcrumbs=array(
'$label'=>array('index'),
'Create',
);\n";
?>

$this->menu=array(
array('label'=>'Manage <?php echo $this->modelClass; ?>', 'url'=>array('index')),
);
?>

<h1>Create <?php echo $this->modelClass; ?></h1>

<?php echo "<?php echo \$this->renderPartial('_form', array('model'=>\$model)); ?>"; ?>
87 changes: 87 additions & 0 deletions gii/mongoCRUD/templates/withoutAdminView/index.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
<?php
/**
* The following variables are available in this template:
* - $this: the CrudCode object
*/
?>
<?php
echo "<?php\n";
$label=$this->pluralize($this->class2name($this->modelClass));
echo "\$this->breadcrumbs=array(
'$label'=>array('index'),
'Manage',
);\n";
?>

$this->menu=array(
array('label'=>'List <?php echo $this->modelClass; ?>', 'url'=>array('index')),
array('label'=>'Create <?php echo $this->modelClass; ?>', 'url'=>array('create')),
);

Yii::app()->clientScript->registerScript('search', "
$('.search-button').click(function(){
$('.search-form').toggle();
return false;
});
$('.search-form form').submit(function(){
$.fn.yiiGridView.update('<?php echo $this->class2id($this->modelClass); ?>-grid', {
data: $(this).serialize()
});
return false;
});
");

?>

<h1>Manage <?php echo $this->pluralize($this->class2name($this->modelClass)); ?></h1>

<p>
You may optionally enter a comparison operator (<b>&lt;</b>, <b>&lt;=</b>, <b>&gt;</b>, <b>&gt;=</b>, <b>&lt;&gt;</b>
or <b>=</b>) at the beginning of each of your search values to specify how the comparison should be done.
</p>

<?php echo "<?php echo CHtml::link('Advanced Search','#',array('class'=>'search-button')); ?>"; ?>

<div class="search-form" style="display:none">
<?php echo "<?php \$this->renderPartial('_search',array(
'model'=>\$model,
)); ?>\n"; ?>
</div><!-- search-form -->

<?php echo "<?php"; ?> $this->widget('zii.widgets.grid.CGridView', array(
'id'=>'<?php echo $this->class2id($this->modelClass); ?>-grid',
'dataProvider'=>new EMongoDocumentDataProvider($model->search(), array(
'sort'=>array(
'attributes'=>array(
<?php
$count=0;
foreach($this->modelObject->attributeNames() as $name)
{
if(++$count==7)
echo "\t\t\t\t/*\n";
echo "\t\t\t\t'".$name."',\n";
}
if($count>=7)
echo "\t\t\t\t*/\n";
?>
),
),
)),
'filter'=>$model,
'columns'=>array(
<?php
$count=0;
foreach($this->modelObject->attributeNames() as $name)
{
if(++$count==7)
echo "\t\t/*\n";
echo "\t\t'".$name."',\n";
}
if($count>=7)
echo "\t\t*/\n";
?>
array(
'class'=>'CButtonColumn',
),
),
)); ?>
27 changes: 27 additions & 0 deletions gii/mongoCRUD/templates/withoutAdminView/update.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?php
/**
* The following variables are available in this template:
* - $this: the CrudCode object
*/
?>
<?php
echo "<?php\n";
$nameColumn=$this->guessNameColumn($this->modelObject);
$label=$this->pluralize($this->class2name($this->modelClass));
echo "\$this->breadcrumbs=array(
'$label'=>array('index'),
\$model->{$nameColumn}=>array('view','id'=>\$model->{$this->modelObject->primaryKey()}),
'Update',
);\n";
?>

$this->menu=array(
array('label'=>'Manage <?php echo $this->modelClass; ?>', 'url'=>array('index')),
array('label'=>'Create <?php echo $this->modelClass; ?>', 'url'=>array('create')),
array('label'=>'View <?php echo $this->modelClass; ?>', 'url'=>array('view', 'id'=>$model-><?php echo $this->modelObject->primaryKey(); ?>)),
);
?>

<h1>Update <?php echo $this->modelClass." <?php echo \$model->{$this->modelObject->primaryKey()}; ?>"; ?></h1>

<?php echo "<?php echo \$this->renderPartial('_form', array('model'=>\$model)); ?>"; ?>
Loading

0 comments on commit ae09aa1

Please sign in to comment.