CakePHPのインストールが終わったので何か表示させてみましょう。
フレームワークではコントローラー・アクションなど規則があるので、それに従ってみますがトップページの表示だけうまくいきません。
そのほかはうまく表示れるのですが・・・
はじめからハマりました。
CakePHPではコントローラー名は
「コントローラー名_controller.php」というファイル名で「app/controllers」に保存。
ということになっていますので、
「index_controller.php」というファイルをアップしてみますが、うまくいきません。
indexだけは特別仕様になっているようです。
「/app/config/routes.php」に設定があります。
routes.phpのファイルの中を覗いてみましょう。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
<?php /** * Routes configuration * * In this file, you set up routes to your controllers and their actions. * Routes are very important mechanism that allows you to freely connect * different urls to chosen controllers and their actions (functions). * * PHP versions 4 and 5 * * CakePHP(tm) : Rapid Development Framework (http://cakephp.org) * Copyright 2005-2011, Cake Software Foundation, Inc. (http://cakefoundation.org) * * Licensed under The MIT License * Redistributions of files must retain the above copyright notice. * * @copyright Copyright 2005-2011, Cake Software Foundation, Inc. (http://cakefoundation.org) * @link http://cakephp.org CakePHP(tm) Project * @package cake * @subpackage cake.app.config * @since CakePHP(tm) v 0.2.9 * @license MIT License (http://www.opensource.org/licenses/mit-license.php) */ /** * Here, we are connecting '/' (base path) to controller called 'Pages', * its action called 'display', and we pass a param to select the view file * to use (in this case, /app/views/pages/home.ctp)... */ Router::connect('/', array('controller' => 'pages', 'action' => 'display', 'home')); /** * ...and connect the rest of 'Pages' controller's urls. */ Router::connect('/pages/*', array('controller' => 'pages', 'action' => 'display')); |
ルートにアクセスがあった場合
controller 「pages」 の action 「display」
がコールされるようになっています。
何かトップページに表示してみましょう。
下記ファイルを作成し、「/app/controllers」にアップロードします。
ファイル名:「pages_controller.php」
class PagesController extends AppController {
public $name = “Pages”;
public $uses = null;
public $autoRender = false;
function display(){
echo “トップページの表示”;
}
}
public $name = “Pages”;
public $uses = null;
public $autoRender = false;
function display(){
echo “トップページの表示”;
}
}
人気記事一覧
- MySQL 最大の値・最新の日付データを1つ抽出する方法(MAX)
- [CakePHP] XformHelperの使い方
- Linux: スワップファイル(swp)の削除方法
- HTMLのForm methodとactionについて
- PHPでカンマ区切りデータを配列に入れる方法 (explode)
- [エラー対処] failed to open stream: No such file or directory
- [vsftp] FileZillaから接続できない場合の対処法
- [CSS]ブロック要素(div)の高さを、内部のfloat要素に合わせて自動調整する
- PHP5.1→PHP5.3へバージョンアップする方法(CentOS)
- PHPでテキストを1行ずつ読み込む方法(file_get_contents,explode)
関連記事一覧
- [CakePHP2]beforeFilterで変数を設定
- [CakePHP2]404 Not Found エラーレスポンスの表示
- [CakePHP] Pagenatorでパラメータを追加する方法
- [CakePHP]404 Not Foundページのカスタマイズ方法
- [CakePHP2]ホームページ(トップページ)を指定する方法
- [CakePHP] Cron (shellを使わない)
- [CakePHP] 自作関数の保存先と利用法(Vendor)
- お名前VPS 簡単設定メモ
- [エラー対処] failed to open stream: No such file or directory
- [CakePHP]エラー対処 URL rewriting is not properly configured on your server.