Sorry if this is duplicating an earlier question but I am quite new to the Yii framework and this is a real basic question.
All I want to do is query a table get all the values in a certain column and then display all of them in a view. Here is what some of the code from the view looks like, <? echo CHtml::link($content, array(‘controller/action’)); ?> I haven’t made the pages this will redirect to.
The sql for this is very basic, ‘select <column name> from <table_name>’. I know findByPk(<parameter>) only returns one value, I’ve tried doing $message = <model name>::model()->findAllBySql(‘select <column_name> from <table_name>’); but to no avail… any hints on how to do this most basic of tasks?
macmac, the simplest way is probably to use Gii: Automatic Code Generation (it does scaffolding / basic CRUD generation). You can generate a model and views for your table. If you examine the code, you’ll be able to understand what is going on and modify the code to display only a single column.
right. Using CDbConnection (as above) is useful when the query is out of context for the ActiveRecord, meaning involves more than one tables and unrelated to relationship between tables (that can be handled by AR). That is - AFAIK…