need help to run cakephp programe
Posted: Mon Sep 13, 2010 7:50 am
hai iam new bibe in cake php and iam learning cake php i have read tutorial but some confusion is there.
1 how to check cake php is installed in my pc .
2-.ctp file in not working in my pc.
i have trying some simple coding like:
Ex:
Database table : books
Model class : Book
Controller class : BooksController
View found at : /app/views/books/index.ctp
coding are:
Sample model
<?php
class Book extends AppModel
{
var$name = 'Book';
var$validate = array(
'title' => array(
'rule' => 'notEmpty'
),
'author' => array(
'rule' => 'notEmpty'
)
);
}
?>
Sample Controller
<?php
class BooksControllerextends AppController{
var$name = 'Books';
var$helpers = array('Html','Ajax','Javascript');
function index()
{
$this->set('books', $this->Book->find('all'));
}
function view($id = null) {
$this->Book->id = $id;
$this->set('book', $this->Book->read());
print_r($this->viewVars);
}
}
Sample view
<h1>Books</h1>
<table>
<tr>
<th>Id</th>
<th>Title</th>
<th>Author</th>
</tr>
<?phpforeach($books as $book: ?>
<tr>
<td><?phpecho $book*‘Book'+*'id'+; ?></td>
<td>
<?phpecho $html->link($book*‘Book+*'title'+,
array('controller' => ‘books’, 'action' => 'view', $book*‘Book+*'id'+)); ?>
</td>
<td><?phpecho $book*‘Book+*‘author'+; ?></td>
</tr>
<?phpendforeach; ?>
</table>
i have created three folder under cakephp like model,controller,views and inside views i have save the view file index.ctp but its display simple code.
My query is how to run the sample view file . and where i have to save the file.
Thanks
waiting for your helpful answer....
1 how to check cake php is installed in my pc .
2-.ctp file in not working in my pc.
i have trying some simple coding like:
Ex:
Database table : books
Model class : Book
Controller class : BooksController
View found at : /app/views/books/index.ctp
coding are:
Sample model
<?php
class Book extends AppModel
{
var$name = 'Book';
var$validate = array(
'title' => array(
'rule' => 'notEmpty'
),
'author' => array(
'rule' => 'notEmpty'
)
);
}
?>
Sample Controller
<?php
class BooksControllerextends AppController{
var$name = 'Books';
var$helpers = array('Html','Ajax','Javascript');
function index()
{
$this->set('books', $this->Book->find('all'));
}
function view($id = null) {
$this->Book->id = $id;
$this->set('book', $this->Book->read());
print_r($this->viewVars);
}
}
Sample view
<h1>Books</h1>
<table>
<tr>
<th>Id</th>
<th>Title</th>
<th>Author</th>
</tr>
<?phpforeach($books as $book: ?>
<tr>
<td><?phpecho $book*‘Book'+*'id'+; ?></td>
<td>
<?phpecho $html->link($book*‘Book+*'title'+,
array('controller' => ‘books’, 'action' => 'view', $book*‘Book+*'id'+)); ?>
</td>
<td><?phpecho $book*‘Book+*‘author'+; ?></td>
</tr>
<?phpendforeach; ?>
</table>
i have created three folder under cakephp like model,controller,views and inside views i have save the view file index.ctp but its display simple code.
My query is how to run the sample view file . and where i have to save the file.
Thanks
waiting for your helpful answer....