Kohana php 2.3.4 方法中调用方法
以下代码在 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
从类名来看,它似乎是一个图书馆。您应该从呈现视图的控制器调用该库。我不认为图书馆可以呈现视图。
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.
我可以通过使用
而不是原来的
来让它工作但是,我仍然想知道为什么它最初不起作用。这与我从控制器调用的库有什么关系吗?我无法想象为什么 $this 应该引用该库。
I was able to get this to work by using
instead of the original
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.