com_weblinksに基づいてコンポーネントを作成したいと思います。
このコンポーネントは、カテゴリとリンクを1ページに表示します。
3.0では、1つのビューで2つのモデル(カテゴリモデルとリンクモデル)を使用する方法がわかりません。
最初のアプローチ
これは、コントローラーを次のように変更することで行いました(これはユーザー用のコントローラーです)
function doThis(){ // the action in the controller "user"
// We will add a second model "bills"
$model = $this->getModel ( 'user' ); // get first model
$view = $this->getView ( 'user', 'html' ); // get view we want to use
$view->setModel( $model, true ); // true is for the default model
$billsModel = &$this->getModel ( 'bills' ); // get second model
$view->setModel( $billsModel );
$view->display(); // now our view has both models at hand
}
ビューでは、モデルに対して簡単に操作を行うことができます
function display($tpl = null){
$userModel = &$this->getModel(); // get default model
$billsModel = &$this->getModel('bills'); // get second model
// do something nice with the models
parent::display($tpl); // now display the layout
}
代替アプローチ
ビューでモデルを直接ロードします。
function display($tpl = null){
// assuming the model's class is MycomponentModelBills
// second paramater is the model prefix
$actionsModel = JModel::getInstance('bills', 'MycomponentModel');
}