Kohana php 2.3.4 方法中调用方法

发布于 2024-09-30 01:11:18 字数 838 浏览 1 评论 0原文

以下代码在 Kohana 2.3.4 中生成页面未找到错误,

class Search_Core
{    
    public function result($term)
        {
            $this->search->title = "Search Results";
            $this->search->content = View::factory("search_view");

            $test = $this->pleaseWork("This should be on the screen");
            $this->search->content->test = $test;

            return $this->search;
        }

    public function pleaseWork($word)
        {
            $dude = $word;

            return $dude;
        }

}

我之前曾在同一类的方法中调用过方法,但由于某种原因,这不起作用。我可以用这样的东西替换 $test 变量:

$test = "a bunch of random words";

它不会有问题。我可以在 Kohana 之外写一些类似的东西,它会起作用,但这不是,我不明白为什么。 $test 变量位于 search_view 视图中,正如我所演示的,如果我提供一个字符串而不是调用一个方法,它就可以查找。

错误位于 Kohana.php 第 841 行。

The following code is generating a page not found error with Kohana 2.3.4

class Search_Core
{    
    public function result($term)
        {
            $this->search->title = "Search Results";
            $this->search->content = View::factory("search_view");

            $test = $this->pleaseWork("This should be on the screen");
            $this->search->content->test = $test;

            return $this->search;
        }

    public function pleaseWork($word)
        {
            $dude = $word;

            return $dude;
        }

}

I've called methods within methods of the same class before, but for some reason this is not working. I can replace the $test variable with something like this:

$test = "a bunch of random words";

And it will work no problem. I can write something similar outside of Kohana and it will work, but this is not and I can't fgure out why. The $test variable is in the search_view view and as I demonstrated, it works find if I supply a string as opposed to calling a method.

The error is on Kohana.php line# 841.

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

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

发布评论

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

评论(2

终止放荡 2024-10-07 01:11:18

从类名来看,它似乎是一个图书馆。您应该从呈现视图的控制器调用该库。我不认为图书馆可以呈现视图。

From the name of the class it seems to be a library. you should be calling the library from a controller which renders a view. i dont think a library can render a view.

睫毛溺水了 2024-10-07 01:11:18

我可以通过使用

$test = Search::pleaseWork("This should be on the screen");

而不是原来的

$test = $this->pleaseWork("This should be on the screen");

来让它工作但是,我仍然想知道为什么它最初不起作用。这与我从控制器调用的库有什么关系吗?我无法想象为什么 $this 应该引用该库。

I was able to get this to work by using

$test = Search::pleaseWork("This should be on the screen");

instead of the original

$test = $this->pleaseWork("This should be on the screen");

However, I would still like to know why it didn't work originally. Does it have something to do with this being a library that I'm calling from a controller? I can't imagine why as the $this should be referencing the library.

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