1
0

Added new (clean) yii boilerplate

This commit is contained in:
2014-05-13 12:40:42 +02:00
parent 1d6d975a16
commit 99d29b432b
1983 changed files with 653465 additions and 17 deletions

View File

@@ -0,0 +1,42 @@
<?php
/**
* This is the template for generating the form view for crud.
* The following variables are available in this template:
* - $ID: the primary key name
* - $modelClass: the model class name
* - $columns: a list of column schema objects
*/
?>
<div class="form">
<?php echo "<?php \$form=\$this->beginWidget('CActiveForm', array(
'id'=>'".$this->class2id($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($columns as $column)
{
if($column->isPrimaryKey)
continue;
?>
<div class="row">
<?php echo "<?php echo ".$this->generateActiveLabel($modelClass,$column)."; ?>\n"; ?>
<?php echo "<?php echo ".$this->generateActiveField($modelClass,$column)."; ?>\n"; ?>
<?php echo "<?php echo \$form->error(\$model,'{$column->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 -->

View File

@@ -0,0 +1,35 @@
<?php
/**
* This is the template for generating the form view for crud.
* The following variables are available in this template:
* - $ID: the primary key name
* - $modelClass: the model class name
* - $columns: a list of column schema objects
*/
?>
<div class="wide form">
<?php echo "<?php \$form=\$this->beginWidget('CActiveForm', array(
'action'=>Yii::app()->createUrl(\$this->route),
'method'=>'get',
)); ?>\n"; ?>
<?php foreach($columns as $column): ?>
<?php
$field=$this->generateInputField($modelClass,$column);
if(strpos($field,'password')!==false)
continue;
?>
<div class="row">
<?php echo "<?php echo \$form->label(\$model,'{$column->name}'); ?>\n"; ?>
<?php echo "<?php echo ".$this->generateActiveField($modelClass,$column)."; ?>\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 -->

View File

@@ -0,0 +1,29 @@
<?php
/**
* This is the template for generating the partial view for rendering a single model.
* The following variables are available in this template:
* - $ID: the primary key name
* - $modelClass: the model class name
* - $columns: a list of column schema objects
*/
?>
<div class="view">
<?php
echo "\t<b><?php echo CHtml::encode(\$data->getAttributeLabel('{$ID}')); ?>:</b>\n";
echo "\t<?php echo CHtml::link(CHtml::encode(\$data->{$ID}), array('view', 'id'=>\$data->{$ID})); ?>\n\t<br />\n\n";
$count=0;
foreach($columns as $column)
{
if($column->isPrimaryKey)
continue;
if(++$count==7)
echo "\t<?php /*\n";
echo "\t<b><?php echo CHtml::encode(\$data->getAttributeLabel('{$column->name}')); ?>:</b>\n";
echo "\t<?php echo CHtml::encode(\$data->{$column->name}); ?>\n\t<br />\n\n";
}
if($count>=7)
echo "\t*/ ?>\n";
?>
</div>

View File

@@ -0,0 +1,73 @@
<?php
/**
* This is the template for generating the admin view for crud.
* The following variables are available in this template:
* - $ID: the primary key name
* - $modelClass: the model class name
* - $columns: a list of column schema objects
*/
?>
<?php
echo "<?php\n";
$label=$this->class2name($modelClass,true);
echo "\$this->breadcrumbs=array(
'$label'=>array('index'),
'Manage',
);\n";
?>
$this->menu=array(
array('label'=>'List <?php echo $modelClass; ?>', 'url'=>array('index')),
array('label'=>'Create <?php echo $modelClass; ?>', 'url'=>array('create')),
);
Yii::app()->clientScript->registerScript('search', "
$('.search-button').click(function(){
$('.search-form').toggle();
return false;
});
$('.search-form form').submit(function(){
$('#<?php echo $this->class2id($modelClass); ?>-grid').yiiGridView('update', {
data: $(this).serialize()
});
return false;
});
");
?>
<h1>Manage <?php echo $this->class2name($modelClass,true); ?></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($modelClass); ?>-grid',
'dataProvider'=>$model->search(),
'filter'=>$model,
'columns'=>array(
<?php
$count=0;
foreach($columns as $column)
{
if(++$count==7)
echo "\t\t/*\n";
echo "\t\t'".$column->name."',\n";
}
if($count>=7)
echo "\t\t*/\n";
?>
array(
'class'=>'CButtonColumn',
),
),
)); ?>

View File

@@ -0,0 +1,190 @@
<?php
/**
* This is the template for generating the controller class file for crud.
* The following variables are available in this template:
* - $ID: the primary key name
* - $controllerClass: the controller class name
* - $modelClass: the model class name
*/
?>
<?php echo "<?php\n"; ?>
class <?php echo $controllerClass; ?> extends Controller
{
/**
* @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';
/**
* @var CActiveRecord the currently loaded data model instance.
*/
private $_model;
/**
* @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.
*/
public function actionView()
{
$this->render('view',array(
'model'=>$this->loadModel(),
));
}
/**
* Creates a new model.
* If creation is successful, the browser will be redirected to the 'view' page.
*/
public function actionCreate()
{
$model=new <?php echo $modelClass; ?>;
// Uncomment the following line if AJAX validation is needed
// $this->performAjaxValidation($model);
if(isset($_POST['<?php echo $modelClass; ?>']))
{
$model->attributes=$_POST['<?php echo $modelClass; ?>'];
if($model->save())
$this->redirect(array('view','id'=>$model-><?php echo $ID; ?>));
}
$this->render('create',array(
'model'=>$model,
));
}
/**
* Updates a particular model.
* If update is successful, the browser will be redirected to the 'view' page.
*/
public function actionUpdate()
{
$model=$this->loadModel();
// Uncomment the following line if AJAX validation is needed
// $this->performAjaxValidation($model);
if(isset($_POST['<?php echo $modelClass; ?>']))
{
$model->attributes=$_POST['<?php echo $modelClass; ?>'];
if($model->save())
$this->redirect(array('view','id'=>$model-><?php echo $ID; ?>));
}
$this->render('update',array(
'model'=>$model,
));
}
/**
* Deletes a particular model.
* If deletion is successful, the browser will be redirected to the 'index' page.
*/
public function actionDelete()
{
if(Yii::app()->request->isPostRequest)
{
// we only allow deletion via POST request
$this->loadModel()->delete();
// if AJAX request (triggered by deletion via admin grid view), we should not redirect the browser
if(!isset($_GET['ajax']))
$this->redirect(array('index'));
}
else
throw new CHttpException(400,'Invalid request. Please do not repeat this request again.');
}
/**
* Lists all models.
*/
public function actionIndex()
{
$dataProvider=new CActiveDataProvider('<?php echo $modelClass; ?>');
$this->render('index',array(
'dataProvider'=>$dataProvider,
));
}
/**
* Manages all models.
*/
public function actionAdmin()
{
$model=new <?php echo $modelClass; ?>('search');
$model->unsetAttributes(); // clear any default values
if(isset($_GET['<?php echo $modelClass; ?>']))
$model->attributes=$_GET['<?php echo $modelClass; ?>'];
$this->render('admin',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.
*/
public function loadModel()
{
if($this->_model===null)
{
if(isset($_GET['id']))
$this->_model=<?php echo $modelClass; ?>::model()->findbyPk($_GET['id']);
if($this->_model===null)
throw new CHttpException(404,'The requested page does not exist.');
}
return $this->_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($modelClass); ?>-form')
{
echo CActiveForm::validate($model);
Yii::app()->end();
}
}
}

View File

@@ -0,0 +1,27 @@
<?php
/**
* This is the template for generating the create view for crud.
* The following variables are available in this template:
* - $ID: the primary key name
* - $modelClass: the model class name
* - $columns: a list of column schema objects
*/
?>
<?php
echo "<?php\n";
$label=$this->class2name($modelClass,true);
echo "\$this->breadcrumbs=array(
'$label'=>array('index'),
'Create',
);\n";
?>
$this->menu=array(
array('label'=>'List <?php echo $modelClass; ?>', 'url'=>array('index')),
array('label'=>'Manage <?php echo $modelClass; ?>', 'url'=>array('admin')),
);
?>
<h1>Create <?php echo $modelClass; ?></h1>
<?php echo "<?php echo \$this->renderPartial('_form', array('model'=>\$model)); ?>"; ?>

View File

@@ -0,0 +1,31 @@
<?php
/**
* This is the template for generating the index view for crud.
* The following variables are available in this template:
* - $ID: the primary key name
* - $modelClass: the model class name
* - $columns: a list of column schema objects
*/
?>
<?php
echo "<?php\n";
$label=$this->class2name($modelClass,true);
$route=$modelClass.'/index';
$route[0]=strtolower($route[0]);
echo "\$this->breadcrumbs=array(
'$label',
);\n";
?>
$this->menu=array(
array('label'=>'Create <?php echo $modelClass; ?>', 'url'=>array('create')),
array('label'=>'Manage <?php echo $modelClass; ?>', 'url'=>array('admin')),
);
?>
<h1><?php echo $label; ?></h1>
<?php echo "<?php"; ?> $this->widget('zii.widgets.CListView', array(
'dataProvider'=>$dataProvider,
'itemView'=>'_view',
)); ?>

View File

@@ -0,0 +1,47 @@
<?php
/**
* This is the template for generating the functional test for controller.
* The following variables are available in this template:
* - $controllerID: the controller ID
* - $fixtureName: the fixture name
* - $modelClass: the model class name
*/
?>
<?php echo "<?php\n"; ?>
class <?php echo $modelClass; ?>Test extends WebTestCase
{
public $fixtures=array(
'<?php echo $fixtureName; ?>'=>'<?php echo $modelClass; ?>',
);
public function testShow()
{
$this->open('?r=<?php echo $controllerID; ?>/view&id=1');
}
public function testCreate()
{
$this->open('?r=<?php echo $controllerID; ?>/create');
}
public function testUpdate()
{
$this->open('?r=<?php echo $controllerID; ?>/update&id=1');
}
public function testDelete()
{
$this->open('?r=<?php echo $controllerID; ?>/view&id=1');
}
public function testList()
{
$this->open('?r=<?php echo $controllerID; ?>/index');
}
public function testAdmin()
{
$this->open('?r=<?php echo $controllerID; ?>/admin');
}
}

View File

@@ -0,0 +1,31 @@
<?php
/**
* This is the template for generating the update view for crud.
* The following variables are available in this template:
* - $ID: the primary key name
* - $modelClass: the model class name
* - $columns: a list of column schema objects
*/
?>
<?php
echo "<?php\n";
$nameColumn=$this->guessNameColumn($columns);
$label=$this->class2name($modelClass,true);
echo "\$this->breadcrumbs=array(
'$label'=>array('index'),
\$model->{$nameColumn}=>array('view','id'=>\$model->{$ID}),
'Update',
);\n";
?>
$this->menu=array(
array('label'=>'List <?php echo $modelClass; ?>', 'url'=>array('index')),
array('label'=>'Create <?php echo $modelClass; ?>', 'url'=>array('create')),
array('label'=>'View <?php echo $modelClass; ?>', 'url'=>array('view', 'id'=>$model-><?php echo $ID; ?>)),
array('label'=>'Manage <?php echo $modelClass; ?>', 'url'=>array('admin')),
);
?>
<h1>Update <?php echo $modelClass." <?php echo \$model->{$ID}; ?>"; ?></h1>
<?php echo "<?php echo \$this->renderPartial('_form', array('model'=>\$model)); ?>"; ?>

View File

@@ -0,0 +1,39 @@
<?php
/**
* This is the template for generating the 'view' view for crud.
* The following variables are available in this template:
* - $ID: the primary key name
* - $modelClass: the model class name
* - $columns: a list of column schema objects
*/
?>
<?php
echo "<?php\n";
$nameColumn=$this->guessNameColumn($columns);
$label=$this->class2name($modelClass,true);
echo "\$this->breadcrumbs=array(
'$label'=>array('index'),
\$model->{$nameColumn},
);\n";
?>
$this->menu=array(
array('label'=>'List <?php echo $modelClass; ?>', 'url'=>array('index')),
array('label'=>'Create <?php echo $modelClass; ?>', 'url'=>array('create')),
array('label'=>'Update <?php echo $modelClass; ?>', 'url'=>array('update', 'id'=>$model-><?php echo $ID; ?>)),
array('label'=>'Delete <?php echo $modelClass; ?>', 'url'=>'#', 'linkOptions'=>array('submit'=>array('delete','id'=>$model-><?php echo $ID; ?>),'confirm'=>'Are you sure you want to delete this item?')),
array('label'=>'Manage <?php echo $modelClass; ?>', 'url'=>array('admin')),
);
?>
<h1>View <?php echo $modelClass." #<?php echo \$model->{$ID}; ?>"; ?></h1>
<?php echo "<?php"; ?> $this->widget('zii.widgets.CDetailView', array(
'data'=>$model,
'attributes'=>array(
<?php
foreach($columns as $column)
echo "\t\t'".$column->name."',\n";
?>
),
)); ?>