本文整理汇总了PHP中GxActiveRecord类的典型用法代码示例。如果您正苦于以下问题:PHP GxActiveRecord类的具体用法?PHP GxActiveRecord怎么用?PHP GxActiveRecord使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了GxActiveRecord类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的PHP代码示例。
示例1: loadModel
/**
* 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 mixed $id the ID of the model to be loaded
* @param string $modelClass the model class name
* @return GxActiveRecord the loaded model
*/
public function loadModel($id, $modelClass)
{
$model = GxActiveRecord::model($modelClass)->findByPk($id);
if ($model === null) {
throw new CHttpException(404, Yii::t('app', 'The requested page does not exist.'));
}
return $model;
}
开发者ID:saifulihsan,项目名称:gkkd-jogja,代码行数:15,代码来源:GxController.php
示例2: loadModel
public function loadModel($key, $modelClass)
{
if (is_array($key)) {
return parent::loadModel($key, $modelClass);
}
$staticModel = GxActiveRecord::model($modelClass);
$model = $staticModel->findByPk($key);
if (!$model) {
throw new CHttpException(404, 'The requested page does not exist.');
}
return $model;
}
开发者ID:bartaakos,项目名称:yii-shard-poc,代码行数:12,代码来源:ApiController.php
示例3: getRelations
/**
* Returns all the relations of the specified model.
* @param string $modelClass The model class name.
* @return array The relations. Each array item is
* a relation as an array, having 3 items:
* 0: the relation name,
* 1: the relation type,
* 2: the foreign key,
* 3: the related active record class name.
* Or an empty array if no relations were found.
*/
public function getRelations($modelClass) {
$relations = GxActiveRecord::model($modelClass)->relations();
$result = array();
foreach ($relations as $relationName => $relation) {
$result[] = array(
$relationName, // the relation name
$relation[0], // the relation type
$relation[2], // the foreign key
$relation[1] // the related active record class name
);
}
return $result;
}
开发者ID:rapbore,项目名称:comar,代码行数:24,代码来源:GiixCrudCode.php
示例4: array
<?php
$this->breadcrumbs = array($model->label(2) => array('index'), GxHtml::valueEx($model));
$this->menu = array(array('label' => Yii::t('app', 'List') . ' ' . $model->label(2), 'url' => array('index')), array('label' => Yii::t('app', 'Create') . ' ' . $model->label(), 'url' => array('create')), array('label' => Yii::t('app', 'Update') . ' ' . $model->label(), 'url' => array('update', 'id' => $model->id)), array('label' => Yii::t('app', 'Delete') . ' ' . $model->label(), 'url' => '#', 'linkOptions' => array('submit' => array('delete', 'id' => $model->id), 'confirm' => 'Are you sure you want to delete this item?')), array('label' => Yii::t('app', 'Manage') . ' ' . $model->label(2), 'url' => array('admin')));
?>
<h1><?php
echo Yii::t('app', 'View') . ' ' . GxHtml::encode($model->label()) . ' ' . GxHtml::encode(GxHtml::valueEx($model));
?>
</h1>
<?php
$this->widget('zii.widgets.CDetailView', array('data' => $model, 'attributes' => array('id', array('name' => 'cupo', 'type' => 'raw', 'value' => $model->cupo !== null ? GxHtml::link(GxHtml::encode(GxHtml::valueEx($model->cupo)), array('cupo/view', 'id' => GxActiveRecord::extractPkValue($model->cupo, true))) : null), array('name' => 'user', 'type' => 'raw', 'value' => $model->user !== null ? GxHtml::link(GxHtml::encode(GxHtml::valueEx($model->user)), array('user/view', 'id' => GxActiveRecord::extractPkValue($model->user, true))) : null), array('name' => 'recarga', 'type' => 'raw', 'value' => $model->recarga !== null ? GxHtml::link(GxHtml::encode(GxHtml::valueEx($model->recarga)), array('recarga/view', 'id' => GxActiveRecord::extractPkValue($model->recarga, true))) : null), 'fecha', 'comentario', 'estado')));
开发者ID:rapbore,项目名称:rch2,代码行数:13,代码来源:view.php
示例5: array
<?php
$this->breadcrumbs = array($model->label(2) => array('index'), GxHtml::valueEx($model) => array('view', 'id' => GxActiveRecord::extractPkValue($model, true)), Yii::t('app', 'Update'));
$this->menu = array(array('label' => Yii::t('app', 'Manage') . ' ' . IguCompanytype::label(2), 'url' => array('admin')));
$this->beginWidget('zii.widgets.CPortlet', array('htmlOptions' => array('class' => '')));
$this->widget('bootstrap.widgets.TbMenu', array('type' => 'pills', 'items' => array(array('label' => 'Create', 'icon' => 'icon-plus', 'url' => Yii::app()->controller->createUrl('create'), 'linkOptions' => array()), array('label' => 'List', 'icon' => 'icon-th-list', 'url' => Yii::app()->controller->createUrl('index'), 'linkOptions' => array()), array('label' => 'Manage', 'icon' => 'icon-search', 'url' => Yii::app()->controller->createUrl('admin'), 'linkOptions' => array('class' => 'search-button')), array('label' => 'Export to PDF', 'icon' => 'icon-download', 'url' => Yii::app()->controller->createUrl('GeneratePdf'), 'linkOptions' => array('target' => '_blank'), 'visible' => true), array('label' => 'Export to Excel', 'icon' => 'icon-download', 'url' => Yii::app()->controller->createUrl('GenerateExcel'), 'linkOptions' => array('target' => '_blank'), 'visible' => true))));
$this->endWidget();
?>
<h3><?php
echo Yii::t('app', 'Update') . ' ' . GxHtml::encode($model->label()) . ' ' . GxHtml::encode(GxHtml::valueEx($model));
?>
</h3>
<?php
$this->renderPartial('_form', array('model' => $model));
开发者ID:cntabana,项目名称:inyungu,代码行数:16,代码来源:update.php
示例6: array
<?php
$this->breadcrumbs = array($model->label(2) => array('index'), GxHtml::valueEx($model));
$this->menu = array(array('label' => Yii::t('app', 'List') . ' ' . $model->label(2), 'url' => array('index')), array('label' => Yii::t('app', 'Create') . ' ' . $model->label(), 'url' => array('create')), array('label' => Yii::t('app', 'Update') . ' ' . $model->label(), 'url' => array('update', 'id' => $model->id)), array('label' => Yii::t('app', 'Delete') . ' ' . $model->label(), 'url' => '#', 'linkOptions' => array('submit' => array('delete', 'id' => $model->id), 'confirm' => 'Are you sure you want to delete this item?')), array('label' => Yii::t('app', 'Manage') . ' ' . $model->label(2), 'url' => array('admin')));
?>
<h1><?php
echo Yii::t('app', 'View') . ' ' . GxHtml::encode($model->label()) . ' ' . GxHtml::encode(GxHtml::valueEx($model));
?>
</h1>
<?php
$this->widget('zii.widgets.CDetailView', array('data' => $model, 'attributes' => array('id', array('name' => 'idclient0', 'type' => 'raw', 'value' => $model->idclient0 !== null ? GxHtml::link(GxHtml::encode(GxHtml::valueEx($model->idclient0)), array('iguRegistration/view', 'id' => GxActiveRecord::extractPkValue($model->idclient0, true))) : null), 'idproduct', 'cashinvested', 'cashprofit', 'year')));
?>
开发者ID:cntabana,项目名称:inyungu,代码行数:14,代码来源:view.php
示例7: array
<?php
$this->breadcrumbs = array($model->label(2) => array('index'), GxHtml::valueEx($model));
$this->menu = array(array('label' => Yii::t('app', 'Listar') . ' ' . $model->label(2), 'url' => array('index')), array('label' => Yii::t('app', 'Crear') . ' ' . $model->label(), 'url' => array('create')), array('label' => Yii::t('app', 'Actualizar') . ' ' . $model->label(), 'url' => array('update', 'id' => $model->iddocumentoexistente)), array('label' => Yii::t('app', 'Eliminar') . ' ' . $model->label(), 'url' => '#', 'linkOptions' => array('submit' => array('delete', 'id' => $model->iddocumentoexistente), 'confirm' => 'Are you sure you want to delete this item?')), array('label' => Yii::t('app', 'Administrar') . ' ' . $model->label(2), 'url' => array('admin')));
?>
<h1><?php
echo Yii::t('app', 'Ver') . ' ' . GxHtml::encode($model->label()) . ' ' . GxHtml::encode(GxHtml::valueEx($model));
?>
</h1>
<?php
$this->widget('zii.widgets.CDetailView', array('data' => $model, 'attributes' => array('iddocumentoexistente', array('name' => 'documentoanexo', 'type' => 'raw', 'value' => $model->documentoanexo !== null ? GxHtml::link(GxHtml::encode(GxHtml::valueEx($model->documentoanexo)), array('documentoAnexo/view', 'id' => GxActiveRecord::extractPkValue($model->documentoanexo, true))) : null), 'archivo', 'matricula_id', 'docente_id', 'fecha_creacion', 'usuario_id')));
?>
开发者ID:MGGROUP,项目名称:SAMDEPURACION,代码行数:14,代码来源:view.php
示例8: array
<?php
$this->breadcrumbs = array($model->label(2) => array('index'), GxHtml::valueEx($model));
$this->menu = array(array('label' => Yii::t('app', 'Listar') . ' ' . $model->label(2), 'url' => array('index')), array('label' => Yii::t('app', 'Agregar') . ' ' . $model->label(), 'url' => array('create')), array('label' => Yii::t('app', 'Editar') . ' ' . $model->label(), 'url' => array('update', 'id' => $model->id)), array('label' => Yii::t('app', 'Borrar') . ' ' . $model->label(), 'url' => '#', 'linkOptions' => array('submit' => array('delete', 'id' => $model->id), 'confirm' => 'Are you sure you want to delete this item?')), array('label' => Yii::t('app', 'Administrar') . ' ' . $model->label(2), 'url' => array('admin')));
?>
<h1><?php
echo GxHtml::encode($model->label()) . ' ' . GxHtml::encode(GxHtml::valueEx($model));
?>
</h1>
<?php
$this->widget('zii.widgets.CDetailView', array('data' => $model, 'attributes' => array('nombre', array('name' => 'idAreaEmpresa', 'type' => 'raw', 'value' => $model->idAreaEmpresa !== null ? GxHtml::link(GxHtml::encode(GxHtml::valueEx($model->idAreaEmpresa)), array('areasEmpresa/view', 'id' => GxActiveRecord::extractPkValue($model->idAreaEmpresa, true))) : null))));
开发者ID:dev-lav,项目名称:htdocs,代码行数:13,代码来源:view.php
示例9: dataTables
protected function dataTables($aColumns, $modelClass, $customQuery = NULL)
{
$staticModel = GxActiveRecord::model($modelClass);
$sIndexColumn = $staticModel->getTableSchema()->primaryKey;
$namaTabel = $staticModel->tableName();
/*
* Paging
*/
$sLimit = "";
if (isset($_GET['iDisplayStart']) && $_GET['iDisplayLength'] != '-1') {
$sLimit = "LIMIT " . $_GET['iDisplayStart'] . ", " . $_GET['iDisplayLength'];
}
/*
* Ordering
*/
$sOrder = "";
if (isset($_GET['iSortCol_0'])) {
$sOrder = "ORDER BY ";
for ($i = 0; $i < intval($_GET['iSortingCols']); $i++) {
if ($_GET['bSortable_' . intval($_GET['iSortCol_' . $i])] == "true") {
$sOrder .= "`" . $aColumns[intval($_GET['iSortCol_' . $i])] . "` " . $_GET['sSortDir_' . $i] . ", ";
}
}
$sOrder = substr_replace($sOrder, "", -2);
if ($sOrder == "ORDER BY") {
$sOrder = "";
}
}
/*
* Filtering
* NOTE this does not match the built-in DataTables filtering which does it
* word by word on any field. It's possible to do here, but concerned about efficiency
* on very large tables, and MySQL's regex functionality is very limited
*/
$sWhere = "";
if (isset($_GET['sSearch']) && $_GET['sSearch'] != "") {
$sWhere = "WHERE (";
for ($i = 0; $i < count($aColumns); $i++) {
$sWhere .= "`" . $aColumns[$i] . "` LIKE '%" . $_GET['sSearch'] . "%' OR ";
}
$sWhere = substr_replace($sWhere, "", -3);
$sWhere .= ')';
}
/* Individual column filtering */
for ($i = 0; $i < count($aColumns); $i++) {
if (isset($_GET['bSearchable_' . $i]) && $_GET['bSearchable_' . $i] == "true" && $_GET['sSearch_' . $i] != '') {
if ($sWhere == "") {
$sWhere = "WHERE ";
} else {
$sWhere .= " AND ";
}
$sWhere .= "`" . $aColumns[$i] . "` LIKE '%" . $_GET['sSearch_' . $i] . "%' ";
}
}
if ($customQuery != NULL) {
if (strlen(trim($sWhere)) == 0) {
$sWhere = "WHERE " . $customQuery;
} else {
$sWhere .= " AND " . $customQuery;
}
}
/*
* SQL queries
* Get data to display
*/
$sQuery = "\n\t\t SELECT `" . str_replace(" , ", " ", implode("`, `", $aColumns)) . "`\n\t\t FROM {$namaTabel}\n\t\t {$sWhere}\n\t\t {$sOrder}\n\t\t {$sLimit}\n\t\t ";
//echo $sQuery;
$rResult = Yii::app()->db->createCommand($sQuery)->queryAll();
/* Data set length after filtering */
$sQuery = "SELECT COUNT(*) AS FR\n\t\t FROM {$namaTabel}\n\t\t {$sWhere}\n\t\t {$sOrder}";
$rResultFilterTotal = Yii::app()->db->createCommand($sQuery)->queryAll();
foreach ($rResultFilterTotal as $v) {
$aResultFilterTotal = $v;
}
$iFilteredTotal = $aResultFilterTotal["FR"];
/* Total data set length */
$sQuery = "\n\t\t SELECT COUNT(`" . $sIndexColumn . "`) as total\n\t\t FROM {$namaTabel}";
if ($customQuery != NULL) {
$sQuery .= " WHERE " . $customQuery;
}
$rResultTotal = Yii::app()->db->createCommand($sQuery)->queryAll();
$i = 0;
$iTotal = 0;
foreach ($rResultTotal as $v) {
$iTotal = $v["total"];
}
return array("result" => $rResult, "total" => $iTotal, "filtertotal" => $iFilteredTotal);
}
开发者ID:phpsong,项目名称:hotel-information-system,代码行数:88,代码来源:GxController.php
示例10: array
<?php
/* @var $this TexteController */
/* @var $model Texte */
$this->breadcrumbs = array(Yii::t('app', 'Administration') => $this->createUrl('/admin/index'), $model->label(2) => array('index'), Yii::t('app', 'Update'));
$this->menu = array(array('label' => $model->label() . ' ' . Yii::t('app', 'Create'), 'url' => array('create'), "icon" => "plus-sign"), array('label' => $model->label() . ' ' . Yii::t('app', 'View'), 'url' => array('view', 'id' => GxActiveRecord::extractPkValue($model, true)), "icon" => "eye-open"), array('label' => $model->label() . ' ' . Yii::t('app', 'Delete'), 'url' => '#', 'linkOptions' => array('submit' => array('delete', 'id' => $model->id), 'confirm' => 'Are you sure you want to delete this item?'), "icon" => "remove"));
?>
<h1><?php
echo Yii::t('app', 'Update') . ': ' . GxHtml::encode($model->label()) . ' ' . GxHtml::encode(GxHtml::valueEx($model));
?>
</h1>
<?php
$this->renderPartial('_form', array('model' => $model));
开发者ID:andi98,项目名称:antragsgruen,代码行数:15,代码来源:update.php
示例11: array
<?php
$this->breadcrumbs = array($model->label(2) => array('index'), GxHtml::valueEx($model));
$this->menu = array(array('label' => Yii::t('app', 'List') . ' ' . $model->label(2), 'url' => array('index')), array('label' => Yii::t('app', 'Create') . ' ' . $model->label(), 'url' => array('create')), array('label' => Yii::t('app', 'Update') . ' ' . $model->label(), 'url' => array('update', 'id' => $model->id)), array('label' => Yii::t('app', 'Delete') . ' ' . $model->label(), 'url' => '#', 'linkOptions' => array('submit' => array('delete', 'id' => $model->id), 'confirm' => 'Are you sure you want to delete this item?')), array('label' => Yii::t('app', 'Manage') . ' ' . $model->label(2), 'url' => array('admin')));
?>
<h1><?php
echo Yii::t('app', 'View') . ' ' . GxHtml::encode($model->label()) . ' ' . GxHtml::encode(GxHtml::valueEx($model));
?>
</h1>
<?php
$this->widget('zii.widgets.CDetailView', array('data' => $model, 'attributes' => array('id', array('name' => 'test', 'type' => 'raw', 'value' => $model->test !== null ? GxHtml::link(GxHtml::encode(GxHtml::valueEx($model->test)), array('test/view', 'id' => GxActiveRecord::extractPkValue($model->test, true))) : null), 'name')));
?>
开发者ID:subhra-sekhar,项目名称:yiitest,代码行数:14,代码来源:view.php
示例12: array
<?php
$this->breadcrumbs = array($model->label(2) => array('index'), GxHtml::valueEx($model));
$this->menu = array(array('label' => Yii::t('app', 'List') . ' ' . $model->label(2), 'url' => array('index')), array('label' => Yii::t('app', 'Create') . ' ' . $model->label(), 'url' => array('create')), array('label' => Yii::t('app', 'Update') . ' ' . $model->label(), 'url' => array('update', 'id' => $model->id)), array('label' => Yii::t('app', 'Delete') . ' ' . $model->label(), 'url' => '#', 'linkOptions' => array('submit' => array('delete', 'id' => $model->id), 'confirm' => 'Are you sure you want to delete this item?')), array('label' => Yii::t('app', 'Manage') . ' ' . $model->label(2), 'url' => array('admin')));
?>
<h1><?php
echo Yii::t('app', 'View') . ' ' . GxHtml::encode($model->label()) . ' ' . GxHtml::encode(GxHtml::valueEx($model));
?>
</h1>
<?php
$this->widget('zii.widgets.CDetailView', array('data' => $model, 'attributes' => array('id', array('name' => 'subdistribution', 'type' => 'raw', 'value' => $model->subdistribution !== null ? GxHtml::link(GxHtml::encode(GxHtml::valueEx($model->subdistribution)), array('subdistribution/view', 'id' => GxActiveRecord::extractPkValue($model->subdistribution, true))) : null), array('name' => 'vendor', 'type' => 'raw', 'value' => $model->vendor !== null ? GxHtml::link(GxHtml::encode(GxHtml::valueEx($model->vendor)), array('vendor/view', 'id' => GxActiveRecord::extractPkValue($model->vendor, true))) : null), array('name' => 'phone', 'type' => 'raw', 'value' => $model->phone !== null ? GxHtml::link(GxHtml::encode(GxHtml::valueEx($model->phone)), array('phone/view', 'id' => GxActiveRecord::extractPkValue($model->phone, true))) : null))));
?>
开发者ID:hanihh,项目名称:vvs_v2,代码行数:14,代码来源:view.php
示例13: array
<?php
$this->breadcrumbs = array('Pah Anggarans' => array('index'), GxHtml::valueEx($model));
$this->menu = array(array('label' => Yii::t('app', 'List') . ' PahAnggaran', 'url' => array('index')), array('label' => Yii::t('app', 'Create') . ' PahAnggaran', 'url' => array('create')), array('label' => Yii::t('app', 'Update') . ' PahAnggaran', 'url' => array('update', 'id' => $model->id)), array('label' => Yii::t('app', 'Delete') . ' PahAnggaran', 'url' => '#', 'linkOptions' => array('submit' => array('delete', 'id' => $model->id), 'confirm' => 'Are you sure you want to delete this item?')));
?>
<h1><?php
echo Yii::t('app', 'View');
?>
PahAnggaran #<?php
echo GxHtml::encode(GxHtml::valueEx($model));
?>
</h1>
<?php
$this->widget('zii.widgets.CDetailView', array('data' => $model, 'attributes' => array('id', 'doc_ref', 'periode_bulan', 'periode_tahun', 'trans_date', 'lock', array('label' => 'Users', 'type' => 'raw', 'value' => GxHtml::link(GxHtml::encode(GxHtml::valueEx($model->users)), array('users/view', 'id' => GxActiveRecord::extractPkValue($model->users, true))))), 'itemTemplate' => "<tr class=\"{class}\"><td style=\"width: 120px\"><b>{label}</b></td><td>{value}</td></tr>\n", 'htmlOptions' => array('class' => 'table')));
?>
<!--h2>Pah Anggaran Detils</h2-->
<?php
/*
echo GxHtml::openTag('ul');
foreach($model->pahAnggaranDetils as $relatedModel) {
echo GxHtml::openTag('li');
echo GxHtml::link(GxHtml::encode(GxHtml::valueEx($relatedModel)), array('pahAnggaranDetil/view', 'id' => GxActiveRecord::extractPkValue($relatedModel, true)));
echo GxHtml::closeTag('li');
}
echo GxHtml::closeTag('ul');*/
开发者ID:saifulihsan,项目名称:gkkd-jogja,代码行数:28,代码来源:view.php
示例14: array
<?php
$this->breadcrumbs = array('Pe Donaturs' => array('index'), GxHtml::valueEx($model));
$this->menu = array(array('label' => Yii::t('app', 'List') . ' PeDonatur', 'url' => array('index')), array('label' => Yii::t('app', 'Create') . ' PeDonatur', 'url' => array('create')), array('label' => Yii::t('app', 'Update') . ' PeDonatur', 'url' => array('update', 'id' => $model->id)), array('label' => Yii::t('app', 'Delete') . ' PeDonatur', 'url' => '#', 'linkOptions' => array('submit' => array('delete', 'id' => $model->id), 'confirm' => 'Are you sure you want to delete this item?')));
?>
<h1><?php
echo Yii::t('app', 'View');
?>
PeDonatur #<?php
echo GxHtml::encode(GxHtml::valueEx($model));
?>
</h1>
<?php
$this->widget('zii.widgets.CDetailView', array('data' => $model, 'attributes' => array('id', 'name', 'phone', 'alamat', 'inactive', array('label' => 'PeChartMaster', 'type' => 'raw', 'value' => GxHtml::link(GxHtml::encode(GxHtml::valueEx($model->accountCode)), array('peChartMaster/view', 'id' => GxActiveRecord::extractPkValue($model->accountCode, true))))), 'itemTemplate' => "<tr class=\"{class}\"><td style=\"width: 120px\"><b>{label}</b></td><td>{value}</td></tr>\n", 'htmlOptions' => array('class' => 'table')));
?>
<!--h2>Pe Kas Masuks</h2-->
<?php
/*
echo GxHtml::openTag('ul');
foreach($model->peKasMasuks as $relatedModel) {
echo GxHtml::openTag('li');
echo GxHtml::link(GxHtml::encode(GxHtml::valueEx($relatedModel)), array('peKasMasuk/view', 'id' => GxActiveRecord::extractPkValue($relatedModel, true)));
echo GxHtml::closeTag('li');
}
echo GxHtml::closeTag('ul');*/
开发者ID:saifulihsan,项目名称:gkkd-jogja,代码行数:28,代码来源:view.php
示例15: saveRelated
/**
* Saves the MANY_MANY relations of this record.
* Internally used by {@link saveWithRelated} and {@link saveMultiple}.
* See {@link saveWithRelated} and {@link saveMultiple} for details.
* @param array $relatedData The relation data in the format returned by {@link GxController::getRelatedData}.
* @param boolean $runValidation Whether to perform validation before saving the record.
* @param boolean $batch Whether to try to do the deletes and inserts in batch.
* While batches may be faster, using active record instances provides better control, validation, event support etc.
* Batch is only supported for deletes.
* @return boolean Whether the saving succeeds.
* @see saveWithRelated
* @see saveMultiple
* @throws CException If this record is new.
* @throws CException If this active record has composite PK.
* @uses pivotModels
*/
protected function saveRelated($relatedData, $runValidation = true, $batch = true)
{
if (empty($relatedData)) {
return true;
}
// This active record can't be new for the method to work correctly.
if ($this->getIsNewRecord()) {
throw new CException(Yii::t('giix.messages', 'Cannot save the related records to the database because the main record is new.'));
}
// Save each related data.
foreach ($relatedData as $relationName => $relationData) {
// The pivot model class name.
$pivotClassNames = $this->pivotModels();
$pivotClassName = $pivotClassNames[$relationName];
$pivotModelStatic = GxActiveRecord::model($pivotClassName);
// Get the foreign key names for the models.
$activeRelation = $this->getActiveRelation($relationName);
$relatedClassName = $activeRelation->className;
if (preg_match('/(.+)\\((.+),\\s*(.+)\\)/', $activeRelation->foreignKey, $matches)) {
// By convention, the first fk is for this model, the second is for the related model.
$thisFkName = $matches[2];
$relatedFkName = $matches[3];
}
// Get the primary key value of the main model.
$thisPkValue = $this->getPrimaryKey();
if (is_array($thisPkValue)) {
throw new CException(Yii::t('giix.messages', 'Composite primary keys are not supported.'));
}
// Get the current related models of this relation and map the current related primary keys.
$currentRelation = $pivotModelStatic->findAll(new CDbCriteria(array('select' => $relatedFkName, 'condition' => "{$thisFkName} = :thisfkvalue", 'params' => array(':thisfkvalue' => $thisPkValue))));
$currentMap = array();
foreach ($currentRelation as $currentRelModel) {
$currentMap[] = $currentRelModel->{$relatedFkName};
}
// Compare the current map to the new data and identify what is to be kept, deleted or inserted.
$newMap = $relationData;
$deleteMap = array();
$insertMap = array();
if ($newMap !== null) {
// Identify the relations to be deleted.
foreach ($currentMap as $currentItem) {
if (!in_array($currentItem, $newMap)) {
$deleteMap[] = $currentItem;
}
}
// Identify the relations to be inserted.
foreach ($newMap as $newItem) {
if (!in_array($newItem, $currentMap)) {
$insertMap[] = $newItem;
}
}
} else {
// If the new data is empty, everything must be deleted.
$deleteMap = $currentMap;
}
// If nothing changed, we simply continue the loop.
if (empty($deleteMap) && empty($insertMap)) {
continue;
}
// Now act inserting and deleting the related data: first prepare the data.
// Inject the foreign key names of both models and the primary key value of the main model in the maps.
foreach ($deleteMap as &$deleteMapPkValue) {
$deleteMapPkValue = array_merge(array($relatedFkName => $deleteMapPkValue), array($thisFkName => $thisPkValue));
}
unset($deleteMapPkValue);
// Clear reference;
foreach ($insertMap as &$insertMapPkValue) {
$insertMapPkValue = array_merge(array($relatedFkName => $insertMapPkValue), array($thisFkName => $thisPkValue));
}
unset($insertMapPkValue);
// Clear reference;
// Now act inserting and deleting the related data: then execute the changes.
// Delete the data.
if (!empty($deleteMap)) {
if ($batch) {
// Delete in batch mode.
if ($pivotModelStatic->deleteByPk($deleteMap) !== count($deleteMap)) {
return false;
}
} else {
// Delete one active record at a time.
foreach ($deleteMap as $value) {
$pivotModel = GxActiveRecord::model($pivotClassName)->findByPk($value);
if (!$pivotModel->delete()) {
//.........这里部分代码省略.........
开发者ID:Rudianasaja,项目名称:cycommerce,代码行数:101,代码来源:GxActiveRecord.php
示例16: array
<?php
echo '<?php';
?>
$this->widget('bootstrap.widgets.TbDetailView', array(
'data' => $model,
'attributes' => array(
<?php
foreach ($this->tableSchema->columns as $column) {
echo $this->generateDetailViewAttribute($this->modelClass, $column) . ",\n";
}
?>
),
)); ?>
<?php
foreach (GxActiveRecord::model($this->modelClass)->relations() as $relationName => $relation) {
if ($relation[0] == GxActiveRecord::HAS_MANY || $relation[0] == GxActiveRecord::MANY_MANY) {
?>
<h2><?php
echo '<?php';
?>
echo GxHtml::encode($model->getRelationLabel('<?php
echo $relationName;
?>
')); ?></h2>
<?php
echo "<?php\n";
?>
echo GxHtml::openTag('ul');
foreach($model-><?php
echo $relationName;
开发者ID:rapbore,项目名称:rch2,代码行数:31,代码来源:view.php
示例17: loadModel
public function loadModel($key, $modelClass)
{
// Get the static model.
$staticModel = GxActiveRecord::model($modelClass);
if (is_array($key)) {
// The key is an array.
// Check if there are column names indexing the values in the array.
reset($key);
if (key($key) === 0) {
// There are no attribute names.
// Check if there are multiple PK values. If there's only one, start again using only the value.
if (count($key) === 1) {
return $this->loadModel($key[0], $modelClass);
}
// Now we will use the composite PK.
// Check if the table has composite PK.
$tablePk = $staticModel->getTableSchema()->primaryKey;
if (!is_array($tablePk)) {
throw new CHttpException(400, Yii::t('giix', 'Your request is invalid.'));
}
// Check if there are the correct number of keys.
if (count($key) !== count($tablePk)) {
throw new CHttpException(400, Yii::t('giix', 'Your request is invalid.'));
}
// Get an array of PK values indexed by the column names.
$pk = $staticModel->fillPkColumnNames($key);
// Then load the model.
$model = $staticModel->findByPk($pk);
} else {
// There are attribute names.
// Then we load the model now.
$model = $staticModel->findByAttributes($key);
}
} else {
// The key is not an array.
// Check if the table has composite PK.
$tablePk = $staticModel->getTableSchema()->primaryKey;
if (is_array($tablePk)) {
// The table has a composite PK.
// The key must be a string to have a PK separator.
if (!is_string($key)) {
throw new CHttpException(400, Yii::t('giix', 'Your request is invalid.'));
}
// There must be a PK separator in the key.
if (stripos($key, GxActiveRecord::$pkSeparator) === false) {
throw new CHttpException(400, Yii::t('giix', 'Your request is invalid.'));
}
// Generate an array, splitting by the separator.
$keyValues = explode(GxActiveRecord::$pkSeparator, $key);
// Start again using the array.
return $this->loadModel($keyValues, $modelClass);
} else {
// The table has a single PK.
// Then we load the model now.
$model = $staticModel->findByPk($key);
}
}
// Check if we have a model.
if ($model === null) {
throw new CHttpException(404, Yii::t('giix', 'The requested page does not exist.'));
}
return $model;
}
开发者ID:ngdvan,项目名称:lntguitar,代码行数:63,代码来源:AdminController.php
示例18: array
<?php
$this->breadcrumbs = array('Pah Sub Aktivitases' => array('index'), GxHtml::valueEx($model) => array('view', 'id' => GxActiveRecord::extractPkValue($model, true)), Yii::t('app', 'Update'));
$this->menu = array(array('label' => Yii::t('app', 'List') . ' PahSubAktivitas', 'url' => array('index')), array('label' => Yii::t('app', 'Create') . ' PahSubAktivitas', 'url' => array('create')), array('label' => Yii::t('app', 'View') . ' PahSubAktivitas', 'url' => array('view', 'id' => GxActiveRecord::extractPkValue($model, true))));
?>
<h1><?php
echo Yii::t('app', 'Update');
?>
PahSubAktivitas #<?php
echo GxHtml::encode(GxHtml::valueEx($model));
?>
</h1>
<?php
$this->renderPartial('_form', array('model' => $model));
开发者ID:saifulihsan,项目名称:gkkd-jogja,代码行数:16,代码来源:update.php
示例19: selectData
/**
* Generates the select data suitable for list-based HTML elements.
* The select data has the attribute or related data as returned
* by {@link CHtml::resolveValue}.
* If the select data comes from a MANY_MANY or a HAS_MANY related
* attribute (is a model or an array of models), it is transformed
* to a string or an array of strings with the selected primary keys.
* @param mixed $value The value of the attribute as returned by
* {@link CHtml::resolveValue}.
* @return mixed The select data.
*/
public static function selectData($value)
{
// If $value is a model or an array of models, turn it into
// a string or an array of strings with the pk values.
if (is_object($value) && is_subclass_of($value, 'GxActiveRecord') || is_array($value) && !empty($value) && is_object($value[0]) && is_subclass_of($value[0], 'GxActiveRecord')) {
return GxActiveRecord::extractPkValue($value, true);
} else {
return $value;
}
}
开发者ID:MGGROUP,项目名称:SAMDEPURACION,代码行数:21,代码来源:GxHtml.php
示例20: array
echo GxHtml::openTag('li');
echo GxHtml::link(GxHtml::encode(GxHtml::valueEx($relatedModel)), array('actor/view', 'id' => GxActiveRecord::extractPkValue($relatedModel, true)));
echo GxHtml::closeTag('li');
}
echo GxHtml::closeTag('ul');
?>
<h2><?php
echo GxHtml::encode($model->getRelationLabel('categories'));
?>
</h2>
<?php
echo GxHtml::openTag('ul');
foreach ($model->categories as $relatedModel) {
echo GxHtml::openTag('li');
echo GxHtml::link(GxHtml::encode(GxHtml::valueEx($relatedModel)), array('category/view', 'id' => GxActiveRecord::extractPkValue($relatedModel, true)));
echo GxHtml::closeTag('li');
}
echo GxHtml::closeTag('ul');
?>
<h2><?php
echo GxHtml::encode($model->getRelationLabel('inventories'));
?>
</h2>
<?php
echo GxHtml::openTag('ul');
foreach ($model->inventories as $relatedModel) {
echo GxHtml::openTag('li');
echo GxHtml::link(GxHtml::encode(GxHtml::valueEx($relatedModel)), array('inventory/view', 'id' => GxActiveRecord::extractPkValue($relatedModel, true)));
echo GxHtml::closeTag('li');
}
echo GxHtml::closeTag('ul');
开发者ID:schmunk42,项目名称:yii-sakila-crud,代码行数:31,代码来源:view.php
注:本文中的GxActiveRecord类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论