In my cakephp i need to retrieve datas from database.
how can i display the table result in neat format.
Controller:
function MarketingTaskmanagement(){
$data['list'] = $this->TravancoAdmin->get_task_all();
$this->set($data);
$this->render('Marketing/taskmanagement');
}
Model:
function get_task_all(){
$users = $this->query('select * from tbl_tasks');
if($users){
return $users;
}else{
return 1;
}
}
View:
But it displays values as so many arrays:
Array ( [0] => Array ( [tbl_tasks] => Array ( [task_ids_mm] => 1 [task_title_mm] => ghjg [task_description_mm] => gjg [task_from_mm] => 09/04/2012 [task_to_mm] => 09/27/2012 ) ) [1] => Array ( [tbl_tasks] => Array ( [task_ids_mm] => 2 [task_title_mm] => hf [task_description_mm] => hfgh [task_from_mm] => 09/03/2012 [task_to_mm] => 09/27/2012 ) ) [2] => Array ( [tbl_tasks] => Array ( [task_ids_mm] => 3 [task_title_mm] => hf [task_description_mm] => hfgh [task_from_mm] => 09/03/2012 [task_to_mm] => 09/27/2012 ) ) [3] => Array ( [tbl_tasks] => Array ( [task_ids_mm] => 4 [task_title_mm] => hfh [task_description_mm] => fgh [task_from_mm] => 09/03/2012 [task_to_mm] => 09/20/2012 ) ) [4] => Array ( [tbl_tasks] => Array ( [task_ids_mm] => 5 [task_title_mm] => h [task_description_mm] => h [task_from_mm] => 09/04/2012 [task_to_mm] => 09/28/2012 ) ) [5] => Array ( [tbl_tasks] => Array ( [task_ids_mm] => 6 [task_title_mm] => hjk [task_description_mm] => hk [task_from_mm] => 09/05/2012 [task_to_mm] => 09/22/2012 ) ) [6] => Array ( [tbl_tasks] => Array ( [task_ids_mm] => 7 [task_title_mm] => v [task_description_mm] => v [task_from_mm] => 09/03/2012 [task_to_mm] => 09/28/2012 ) ) [7] => Array ( [tbl_tasks] => Array ( [task_ids_mm] => 8 [task_title_mm] => d [task_description_mm] => d [task_from_mm] => 09/03/2012 [task_to_mm] => 09/28/2012 ) ) [8] => Array ( [tbl_tasks] => Array ( [task_ids_mm] => 9 [task_title_mm] => f [task_description_mm] => d [task_from_mm] => 09/04/2012 [task_to_mm] => 09/27/2012 ) ) [9] => Array ( [tbl_tasks] => Array ( [task_ids_mm] => 10 [task_title_mm] => b [task_description_mm] => b [task_from_mm] => 09/05/2012 [task_to_mm] => 09/27/2012 ) ) )
In codeigniter there have something like this:
$users = $this->query('select * from tbl_tasks')->result();
Then it displays the correct array without any complication .
So how can i do this in cakephp?
And i need to display the all task_title_mm values from the table result in view page.
How can i do this?
Since you expanded your question I’ll elaborate a bit on the anwser.
It is a good practice to not use
$this->query()where a native cake search would work.if you don’t have a model file for your
tbl_taskscreate one:Load it inside your
get_task_all()function. You can load a model dinamically inside another.find('list')works if you declare'task_title_mm'as displayField otherwise you can use$this->Task->find('all', array('fields' => array('task_title_mm')));, but the result will be prefixed with['Task'];