0
votes

I'am a beginner in cakephp and i have installed it , and i start every thing perfectly , But the problem is when i use the index.ctp which in view/Posts folder code is

<?php echo $v; ?>   

and the PostsController.php code is

class PostsController extends AppController {

public $name = 'Posts';

public function index(){
    $this->set('v',$this->Post->findById('all'));
    }}

But the php code not displays nothing

please help i have to start fast because am going to be tested to get a job

1
$v is an array, not a string, so you need to do pr($v) instead of the echo. Also, a sidenote, if you are going to be tested to get a job, you should probably start on how to be a master at debugging and researching first.Nunser

1 Answers

0
votes

findById('all') is wrong , findById(ID) is true

example => findById(2) for fetch a record of Post that Post.id is 2

i think u want fetch all Post data , so.. do this :

in your controller:

public function index(){
   $this->set('v',$this->Post->find('all'));
}

and in view:

foreach($v as $value){
     echo $value['FIELD_NAME'];
}