views:

40

answers:

2

Hello I have been trying to understand how to get data from model by the name of field. I am using cakePHP, and I need to retreive a column's data from a table. The syntax is

> "select name from permissions"

So I tried to find out on book.cakephp.org, so I got the field function, but that only gives me the first value, while I have more than one values for this.

I tried do a $this->Model->find(array('fields'=>'Model.fieldName'));, but I understood that the syntax itself is flawed.

Can somebody let me know what is the method to query based on column name.

+1  A: 
$this->Model->find(array('fields'=>'Model.fieldName'))

You forgot the array function. Also:

$this->Model->find(array('fields'=>array('Model.fieldName')))

will work.

webbiedave
Well the syntax I gave in the question was wrong, when I do that, it adds "where fields='Model.name'" bit to the original sql. It isn't querying based on field name.
macha
A: 

There is no way you can query out based on column name using one of the cake methods. You have to use the query method.

Syntax: $this->Model->('Select columnname from table');

taktak