CakePHP View

View is like template of pages. It display pages.

index.ctp

<h1>Index Page</h1>
<p>this is test View.</p>
<p>message: <?php echo $msg; ?></p>
<p> </p>
<p>Data.</p>
<div>
    <ul>
    <?php foreach($datas as $data): ?>
    <li><?php echo $data; ?></li>
    <?php endforeach; ?>
    </ul>
</div>
<p>NUM </p>
<p> <?php echo $num; ?></p>

SampleController.php

<?php
App::uses('AppController', 'Controller');
class SampleController extends AppController {
    public function index(){
       $this->set("title_for_layout", "Index Page");
       $this->set("msg", "hello");
       $this->set("num", 1);
       $this->set("datas", array("one", "two"));
    }
}
Remove all ads