私は過去数か月間 Yii を使用してきましたが、ちょっとした障害にぶつかりました。
私のベースコントローラーには、public $currentUserOrganisations = NULL;
ロード時にログインしているすべてのユーザー組織を入力するプロパティがあります。
これで、すべての組織を取得し、ユーザーがそれらに接続できるページができましたが、既に持っている組織は、追加する機能ではなく、「接続済み」と表示する必要があります。私はブートストラップTbGridView
ウィジェットを使用しており、私のOrganisation
モデルgetConnectionAction
では、組織が既にユーザーに接続されているかどうかに応じて、アンカーまたはラベルを返す関数を作成しました。
ここに私の問題があります。モデルにすでにロードされているユーザー組織にアクセスする方法が見つかりませんOrganisation
。これは、モデル クラスのプロパティであるためです。
コードについては以下を参照してください。
コントローラーでのアクション
public function actionNew()
{
$connectionModel = Connection::model();
$organizationModel = Organisation::model();
$this->selectedSubnav = "Add";
$this->render('new', array("connectionModel" => $connectionModel, "organizationModel" => $organizationModel));
}
ビュー内の TbGridView は次のとおりです。
<?php
$this->widget(
'bootstrap.widgets.TbGridView',
array(
'type'=>'striped',
'enableSorting'=>true,
'id' => 'connection-rest-data',
'dataProvider' => $organizationModel->getConnectionsByOrganization($this->currentOrganisation->id),
'ajaxUpdate' => true,
'template'=>"{pager}<br>\n{items}\n{pager}",
'rowHtmlOptionsExpression' => '',
'emptyText' => Yii::t("site", "no_restults_found") . '.',
"itemsCssClass" => "table table-first-column-number data-table display full dataTable transaction_tbl",
'columns' => array(
array(
'header' => Yii::t("site", "id"),
'value' => '$data->id',
'type' => 'raw',
'name' => 'id'
),
array(
'header' => Yii::t("site", "from_unit"),
'type' => 'raw',
'value' => '$data->fromUnit["name"]',
'name' => 'fromUnit'
),
array(
'header' => Yii::t("site", "to_unit"),
'type' => 'raw',
'value' => '$data->toUnit["name"]',
'name' => 'type'
),
array(
'header' => Yii::t("site", "connection_type"),
'type' => 'raw',
'value' => '$data->type["name"]',
'name' => 'type'
),
array(
'header' => Yii::t("site", "ended"),
'type' => 'raw',
'value' => '$data->ended',
'name' => 'ended'
),
array(
'header' => Yii::t("site", "fees"),
'type' => 'raw',
'value' => 'empty($data->fees) ? "none" : $data->fees["fee"]',
'name' => 'fees'
),
array(
'header' => Yii::t("site", "actions"),
'type' => 'raw',
'value' => 'Organisation::model()->getConnectionAction($data->id, \'' . serialize($this->currentUserOrganisations) . '\'")',
'name' => 'fees'
)
),
)
);
?>
Organisations
モデルの関数は次のとおりです。
public function getConnectionAction ($connectionId)
{
$currentOrganizations = null; //This I need to get the public $currentUserOrganisations = NULL; value
foreach ($currentOrganizations as $org)
{
if($org->id == $connectionId)
{
return CHtml::label(Yii::t("site", "connected"), "", array("style" => "color:green;"));
}
}
return CHtml::link("Add", "/connection/manage/addConnection?id=$connectionId");
}
皆さんに感謝します。不明な点があれば大声で言ってください!