アプリ版:「スタンプのみでお礼する」機能のリリースについて

CodeIgniterというフレームワークを利用してサイトを作成しようとしているのですが、うまく行きません。
index.phpというファイルに
class Index extends CI_Controller {
public function index()
{
$this->load->view('index');
}
}
としてviewフォルダにindex.phpというHTML主体のファイルを格納しました。
意図したページの表示が出ません。
色々調べたのですが、URLを簡素化する
.htaccessの内容も
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ index.php?$1 [L]
(A PHP Error was encountered
Severity: Notice
Message: Undefined property: Index::$load
Filename: controllers/index.php
Line Number: 7 というエラーが出ます)
という例と
RewriteEngine on
RewriteCond $1 !^(index\.php|images|robots\.txt)
RewriteRule ^(.*)$ /index.php/$1 [L]
(No input file specified.というエラーが出ます)
という例があり2パターンがありますが、どちらが正解でしょうか?
まだはじめたばかりでわからない事ばかりで教えて下さい。

A 回答 (2件)

まず、controllers/index.php ですが、PHPではクラス名と同名のメソッドはコンストラクタ扱いされます。


従って、「 Index 」クラスで「 index() 」メソッドを定義する場合は、「 __construct() 」を定義しないと親クラスである「 CI_Controller 」のコンストラクタが処理されません。

class Index extends CI_Controller {

public function __construct()
{
parent::__construct();
}

public function index()
{
$this->load->view('index');
}

}

.htaccessですが、
本家のマニュアルに記載されている「 mod_rewrite 」の記述は間違っています。
正しくは↓です。

RewriteEngine on
RewriteCond $1 !^/(index\.php|php\.php|favicon\.ico|images|css|js|sitemap.xml|robots\.txt)
RewriteRule ^(.*)$ /index.php/$1 [L]

「 RewriteCond 」の「 (index 」の前に「 / 」スラッシュが必要です。

詳しくは
http://www.ci-guide.info/basic/controller/
http://www.ci-guide.info/basic/uri/
こちらのサイトを参考になさると良いかもしれません。

参考URL:http://www.ci-guide.info/
    • good
    • 0

.htaccessでの記述では「 (index 」の前の「 / 」スラッシュは不要のようです。



httpd.conf で記述する場合に必要でした。
    • good
    • 0

お探しのQ&Aが見つからない時は、教えて!gooで質問しましょう!