In Yii 2.0, I was trying to encode or print a query result to XML format in order to access to these data by using REST, but when I push the result of the query (located it in an ActiveController) into de view, I get a huge html code and the query result inside of it.
This is my ActiveController, and my function actionSql() to render the sql.php view:
class EventController extends ActiveController{
public $modelClass = 'app\models\Event';
public function behaviors()
{
return ArrayHelper::merge(parent::behaviors(), [
'verbs' => [
'class' => VerbFilter::className(),
'actions' => [
'delete' => ['post'],
],
],
]);
}
public function actionSql(){
$rows = (new Query())
->select(['ta.id', 'e.name', 'e.desc', 'u.place', 'u.date'])
->from(['ta' => 't_area'])
->innerJoin('event e', 'ta.id = e.t_area_id')
->innerJoin('ubic u', 'e.id = u.event_id')
->where([
'ta.id' => 1,
'dayname(u.date)' => 'Monday'
])
->all();
return $this->render( 'sql', [
'rows' => $rows,
]);
}
}
===========================
sql.php (The View)
<?php
use yii\helpers\Html;
use yii\grid\GridView;
?>
<?php
foreach ($filas as $fila){
foreach ( $fila as $key=>$value ){
echo $key . ' => ' . $value . '<br>';
}
echo '<br>';
}
?>
Thank you so much. Hope to find the answer!
return $rows