将数据从模块控制器传递到 PyroCMS 中的小部件

发布于 2024-11-18 02:29:42 字数 69 浏览 2 评论 0原文

我可以以编程方式将自定义数据从模块的控制器传递到小部件(当它在模块视图中用作标签时)吗?或者这是否违反了小部件自包含的概念?

Can I pass custom data from the module's controller to widgets(when it is being used as a tag in the module view) programatically? Or does this violate the concept of widgets being self contained?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

や三分注定 2024-11-25 02:29:42

哇,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

Wow, 4 months passed but hope this helps:

Let's say that you have a module named "example" in:

/addons/modules/example/

Create a "widgets" folder under "example" module directory and create your widget there:

In this case widget controller filename will be:

/addons/modules/example/widgets/something/something.php

Its content:

<?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()
       ); 
    }
}

And its view will be in:

/addons/modules/example/widgets/something/views/display.php

View content:

<h2>Some html</h2>
<p>And the variable from controller:</p>
<p><?php echo $variable_name;?></p>

For more info you can look under blog module directory. There you will see widgets.

Otherwise there is always pyrocms.com:

http://www.pyrocms.com/docs/manuals/developers/creating-custom-widgets

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文