代码之家  ›  专栏  ›  技术社区  ›  anthony

在方法Kohana php 2.3.4中调用方法

  •  0
  • anthony  · 技术社区  · 14 年前

    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.php行#841。

    2 回复  |  直到 14 年前
        1
  •  0
  •   zerodin    14 年前

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

        2
  •  0
  •   anthony    14 年前

    我可以通过使用

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

    而不是原来的

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

    不过,我还是想知道为什么它最初不起作用。这和我从控制器调用的库有关系吗?我无法想象为什么作为$这个应该参考图书馆。