title: I need to call a controller function inside a view -Codeigniter
body: <p>I need to call a function from view to echo a value. I use following code,</p>
  
  <p>Controller (test_controller)</p>
  
  <pre><code>public function displayCategory()
      {
          $this-&gt;load-&gt;model('Model_test');
  
          $data['categories'] = $this-&gt;Model_test-&gt;getCategories();
  
          $this-&gt;load-&gt;view('test_view', $data);
      }
  
  public function display($id)
      {
          $this-&gt;load-&gt;model('Model_test');
          $name= $this-&gt;Model_test-&gt;getName($id);
          return $name;
      }
  </code></pre>
  
  <p>Model (Model_test)</p>
  
  <pre><code>function getCategories() {
          $query = $this-&gt;db-&gt;query("SELECT * FROM category");
          if ($query-&gt;num_rows() &gt; 0) {
              return $query-&gt;result();
          } else {
              return NULL;
          }
      }
  
  function getName($userId) {
          $query = $this-&gt;db-&gt;query("SELECT name FROM user where id = '$userId' ");
          if ($query-&gt;num_rows() &gt; 0) {
              return $query-&gt;row()-&gt;name;
          } else {
              return NULL;
          }
      }
  </code></pre>
  
  <p>View</p>
  
  <pre><code>&lt;div id="body"&gt;
  
          &lt;?php                
              foreach ($categories as $object) {
                  $temp = $this-&gt;test_controller-&gt;display($object-&gt;id);
                  echo $object-&gt;title . "&amp;nbsp;&amp;nbsp;". $object-&gt;no . $temp . '&lt;br/&gt;';
              }
          ?&gt;
  
  &lt;/div&gt;
  </code></pre>
  
  <p>but some error when running the code.</p>
  
  <p>error Message: Undefined property: CI_Loader::$test_controller in view</p>