HelloWorld

フォルダ構成


cakephp(root)
  + app
    + controllers
      + sample_controller.php
  + views
    + sample
      + index.ctp
※必要なフォルダの追加などを行っています

コントローラー

controllersフォルダにsampleコントローラーの"sample_controller.php"を作成

<?php
class SampleController extends AppController {
 
    public $name = "Sample";
    public $uses = null;
    public $autoRender = true;
 
    function index(){
        $this->set("title_text","Sample Page");
        $this->set("content","Hello World");
    } 
}
 
 

ビュー

viewsフォルダにコントローラーと同名の"sample"ディレクトリを作成

作成したsampleディレクトリにindex.ctpファイルを作成

<h1><?php echo $title_text; ?></h1>
<br />
<p><?php echo $content; ?></p>
 
 

確認

http://website/sample[/index]で確認




最終更新:2010年10月30日 20:46