title: Get values from for loop in controller-model (php)
body: <p>I use yii framework but I have a php problem here.
  I struggle to get datas from a loop which begins in my controller, continues in my model and ends in my controller.
  Here is my code :</p>
  
  <p>adminController.php</p>
  
  <pre><code>public function actionAdmin()
  {
  ////code generated by gii////
      $model=new vbnm('search');
      $model-&gt;unsetAttributes();  // clear any default values
      if(isset($_GET['vbnm'])){
          $model-&gt;attributes=$_GET['vbnm'];
      }
  
  ////my code////
      $groupid=array();
  
      $dataArray = vbnm::model()-&gt;search()-&gt;getData();
  
      foreach($dataArray as $data){
          $groupid[] = $data-&gt;groupvb['joinvbgroup_group_id'];
      }
      $size = count($groupid);
  
      $values = array();
  
      for ($i=0; $i&lt;$size; $i++){
          $model-&gt;get_user_name($groupid[$i]);
      }
  
      $this-&gt;render('admin',array(
          'model'=&gt;$model,
      ));
  }
  </code></pre>
  
  <p>adminModel.php</p>
  
  <pre><code>public function get_user_name($groupId)
  {           
      $userid = array();
  
      $user = Yii::app()-&gt;db-&gt;createCommand()
      -&gt;select('joinusergroup_user_id')
      -&gt;from('JoinUserGroup')
      -&gt;where('joinusergroup_group_id=:id', array(':id'=&gt;$groupId))
      -&gt;query();
  
      foreach($user as $key=&gt;$value){
          $userid[] = $value['joinusergroup_user_id'];
      }
  
      $size=count($userid);
  
      $username = array();
  
      for($i=0; $i&lt;$size; $i++){
  
          $name = Yii::app()-&gt;db-&gt;createCommand()
          -&gt;select('username')
          -&gt;from('tbl_users')
          -&gt;where('id=:id', array(':id'=&gt;$userid[$i]))
          -&gt;query();
  
          foreach($name as $key=&gt;$value){
              $username[] = $value['username'];
          }
  
          $size_n = count($username);
  
          $uname=array();
  
          for($j=$i; $j&lt;$size_n; $j++){
              $uname[]=$username[$j];
          }
      }   
  }
  </code></pre>
  
  <p>The code works, I get what I want when I log my $userid[$i] and my $username[$j].</p>
  
  <p>My problem is : How can I return the values of $username[$j] in my controller (when my loop ends) to pass it in my view (I want to display it in a CGridView)? If I use a return it will stop my loop, right?
  May I have a bad use of MVC?</p>
  
  <p>Thanks!</p>