Action Index Using Custom Sql

in my controller I have the usual controller for in dex


public function actionIndex()

{


	$dataProvider=new CActiveDataProvider('Faq');


	$this->render('index',array(

	'dataProvider'=>$dataProvider,

	));

	

}

now that dataprovider gets EVERY field in my table… I would like for it to only return certain fields based on a specific condition. in this case a language flag.

how can I pass the following SQL to the provider?


sql = "SELECT faq_id, faq_title_".$lang.", faq_content_".$lang." FROM tbl_faq";

$lang can either be "en" or "fr" in my case

you can use like this




$sql = "SELECT faq_id, faq_title_".$lang.", faq_content_".$lang." FROM tbl_faq";

$dataProvider=new CSqlDataProvider($sql);

//Note: $dataProvider->getData() will return a list of arrays.


$this->render('index',array(

        'dataProvider'=>$dataProvider,

));

I had tried that but this is what I get


Fatal error: Call to a member function getAttributeLabel() on a non-object in /Users/xxx/Sites/cb200/protected/views/faq/_view.php on line 5

and in the view I have this




<div class="view">





	<b><?php echo CHtml::encode($data->getAttributeLabel('faq_title_en')); ?>:</b>

	<?php echo CHtml::encode($data->faq_title_en); ?>

	<br />




	<b><?php echo CHtml::encode($data->getAttributeLabel('faq_content_en')); ?>:</b>

	<?php echo CHtml::encode($data->faq_content_en); ?>

	<br />




</div>

my controller is this


public function actionIndex()

{

//	$dataProvider=new CActiveDataProvider('Faq');

        $lang = getLang();


        $sql = "SELECT faq_id, faq_title_".$lang.", faq_content_".$lang." FROM tbl_faq";

  

        $dataProvider=new CSqlDataProvider($sql);


	$this->render('index',array(

	'dataProvider'=>$dataProvider,

 ));

	

}

what am I missing?

You can pass in a CDbCriteria object (or the configuration settings for one):




$dataProvider=new CActiveDataProvider('Faq', array(

    'criteria'=>array(

        'select'=>array('faq_id', 'faq_title_' . $lang, 'faq_content_' . $lang),

    ),

));



that worked like a charm! thanks for the tips guys