カスタム データをモジュールのコントローラーからウィジェットに渡すことはできますか (モジュール ビューでタグとして使用されている場合)。それとも、これはウィジェットが自己完結型であるという概念に違反していますか?
1 に答える
1
うわー、4か月が経過しましたが、これが役立つことを願っています:
次の場所に「example」という名前のモジュールがあるとします。
/addons/modules/example/
「example」モジュール ディレクトリの下に「widgets」フォルダを作成し、そこにウィジェットを作成します。
この場合、ウィジェット コントローラのファイル名は次のようになります。
/addons/modules/example/widgets/something/something.php
その内容:
<?php defined('BASEPATH') OR exit('No direct script access allowed');
class Widget_Something extends Widgets
{
public $author = 'Author';
public $website = 'site';
public $version = '1.0';
public function run($options)
{
// Load your modules model
$this->load->model("example/example_m");
// And/Or load your modules library
$this->load->library("example/some_library");
// Return values to use in view
return array(
'variable_name' => $this->example_m->get_some_data(),
'variable_name_2' => $this->example_m->get_some_other_data()
);
}
}
そのビューは次のようになります。
/addons/modules/example/widgets/something/views/display.php
コンテンツを見る:
<h2>Some html</h2>
<p>And the variable from controller:</p>
<p><?php echo $variable_name;?></p>
詳細については、ブログ モジュール ディレクトリの下を参照してください。そこにウィジェットが表示されます。
それ以外の場合は、常に pyrocms.com があります。
http://www.pyrocms.com/docs/manuals/developers/creating-custom-widgets
于 2011-10-28T16:36:22.033 に答える