Reputation: 11471
I am a newbie in Cake PHP, and I need to transform my html website to use CakePHP. I am having trouble understanding how it works, but i know that if I make one piece work I should be able to continue building it, I just need that initial help hand that I havent been able to clearly understand in the tutorials. So here is a small scenario from my website
I have a MySql Table called cars
, this table has the following values
car_id
car_name
car_description
car_price
in app/controllers i created my control cars_controller.php
<?php
class CarsController extends AppController {
var $name = 'Cars';
}
?>
in my model I created a Car.php
<?php
class Car extends AppModel{
var $name = 'Car';
}
?>
What I am having issues with, is now... how can I show these cars, how do I set up a view to just show these cars?.. Usually what I did was just had a show_cars.php that had all the mysql logic in there to pull the data and then pass the results to my showcars.html or showcars.php but now I am totally lost, I tried watching YouTube, went to cakephp.org . Still I am not able to understand. Also once I get the cars, how should I type the url (I am in locahost) to access this view?
Any help, will be much appreciated.
Upvotes: 0
Views: 52
Reputation: 100175
Try in your controller:
class CarsController extends AppController {
var $name = 'Cars';
//use model Car
var $uses = array("Car");
public function list() {
$carList = $this->Car->find("all");
//set to display for view list.ctp inside Car folder
$this->set("list_cars", $carList);
}
}
Now create list.ctp
file inside Car folder (this is the view) and do:
print_r($list_cars); // this will show up array of rows from your table
For more info check: http://book.cakephp.org/
Upvotes: 1