FuelPHP ビューが無いエラー追跡メモ

とりあえずコントローラだけ作ってテキトーにURL開いたら下記エラーが発生.

Fuel\Core\FuelException [ Error ]: The requested view could not be found hoge/hoge

なんとなくコード追っかけてみる.


実際に例外投げてるところ

fuel/core/classes/view.php

373 	public function set_filename($file)
374 	{
375 		// set find_file's one-time-only search paths
376 		\Finder::instance()->flash($this->request_paths);
377 
378 		// locate the view file
379 		if (($path = \Finder::search('views', $file, '.'.$this->extension, false, false)) === false)
380 		{
381 			throw new \FuelException('The requested view could not be found: '.\Fuel::clean_path($file));
382 		}
383 
384 		// Store the file path locally
385 		$this->file_name = $path;
386 
387 		return $this;
388 	}

例外発生の原因となっている Finder::search() のコード部分

fuel/core/classes/finder.php

 39 	public static function search($dir, $file, $ext = '.php', $multiple = false, $cache = true)
 40 	{
 41 		return static::instance()->locate($dir, $file, $ext, $multiple, $cache);
 42 	}

試しに下記のような変更を加えてみる

diff --git a/fuel/core/classes/view.php b/fuel/core/classes/view.php
index 457e81f..f5a002b 100644
--- a/fuel/core/classes/view.php
+++ b/fuel/core/classes/view.php
@@ -372,6 +372,8 @@ class View
         */
        public function set_filename($file)
        {
+               var_dump($file);
+               exit;
                // set find_file's one-time-only search paths
                \Finder::instance()->flash($this->request_paths);
 

出力結果.

string(9) "hoge/hoge" 

こんどはココに var_dump() を仕掛けてみる

diff --git a/fuel/core/classes/finder.php b/fuel/core/classes/finder.php
index a710171..6ba066f 100644
--- a/fuel/core/classes/finder.php
+++ b/fuel/core/classes/finder.php
@@ -38,6 +38,8 @@ class Finder
         */
        public static function search($dir, $file, $ext = '.php', $multiple = false, $cache = true)
        {
+               var_dump($file);
+               exit;
                return static::instance()->locate($dir, $file, $ext, $multiple, $cache);
        }

出力結果.

string(6) "config" 

他の名前が出てきた.そりゃそうか.

今度は下記のような変更にしてみる.

diff --git a/fuel/core/classes/finder.php b/fuel/core/classes/finder.php
index a710171..8379a30 100644
--- a/fuel/core/classes/finder.php
+++ b/fuel/core/classes/finder.php
@@ -38,6 +38,7 @@ class Finder
         */
        public static function search($dir, $file, $ext = '.php', $multiple = false, $cache = true)
        {
+               var_dump($file);
                return static::instance()->locate($dir, $file, $ext, $multiple, $cache);
        }
 
diff --git a/fuel/core/classes/view.php b/fuel/core/classes/view.php
index 457e81f..936918b 100644
--- a/fuel/core/classes/view.php
+++ b/fuel/core/classes/view.php
@@ -378,6 +378,7 @@ class View
                // locate the view file
                if (($path = \Finder::search('views', $file, '.'.$this->extension, false, false)) === false)
                {
+                       exit;
                        throw new \FuelException('The requested view could not be found: '.\Fuel::clean_path($file));
                }
 

出力結果

string(6) "config" string(6) "config" string(6) "routes" string(6) "routes" string(4) "file" string(4) "file" string(9) "hoge/hoge" 

なんかよくわからん.

なんか dir とかいう変数があるのでこれも含めて出力してみる.あと改行なくて見にくいのでむりやり追加.

diff --git a/fuel/core/classes/finder.php b/fuel/core/classes/finder.php
index a710171..0db1411 100644
--- a/fuel/core/classes/finder.php
+++ b/fuel/core/classes/finder.php
@@ -38,6 +38,13 @@ class Finder
         */
        public static function search($dir, $file, $ext = '.php', $multiple = false, $cache = true)
        {
+               var_dump($dir);
+               echo '<br />';
+               var_dump($file);
+               echo '<br />';
+               var_dump(static::instance()->locate($dir, $file, $ext, $multiple, $cache));
+               echo '<br />';
+               echo '<br />';
                return static::instance()->locate($dir, $file, $ext, $multiple, $cache);
        }
 
diff --git a/fuel/core/classes/view.php b/fuel/core/classes/view.php
index 457e81f..936918b 100644
--- a/fuel/core/classes/view.php
+++ b/fuel/core/classes/view.php
@@ -378,6 +378,7 @@ class View
                // locate the view file
                if (($path = \Finder::search('views', $file, '.'.$this->extension, false, false)) === false)
                {
+                       exit;
                        throw new \FuelException('The requested view could not be found: '.\Fuel::clean_path($file));
                }
 

出力結果

string(6) "config"
string(6) "config"
array(1) { [0]=> string(**) "/path/to/fule_home/fuel/app/config/config.php" }

string(18) "config/development"
string(6) "config"
array(0) { }

string(6) "config"
string(6) "routes"
array(1) { [0]=> string(**) "/path/to/fule_home/fuel-test/fuel/app/config/routes.php" }

string(18) "config/development"
string(6) "routes"
array(0) { }

string(6) "config"
string(4) "file"
array(1) { [0]=> string(**) "/path/to/fule_home/fuel-test/fuel/core/config/file.php" }

string(18) "config/development"
string(4) "file"
array(0) { }

string(5) "views"
string(9) "hoge/hoge"
bool(false) 


今回必要なのは最後の views ディレクトリの部分っぽいのでこれだけ探してみる

$ find . -name views -type d
./fuel/core/views
./fuel/packages/oil/views
./fuel/packages/oil/views/scaffolding/orm/views
./fuel/packages/oil/views/scaffolding/crud/views
./fuel/packages/oil/views/admin/orm/views
./fuel/packages/oil/views/admin/crud/views
./fuel/app/views

この中で FuelPHP を使って開発する人が触る部分は ./fuel/app/views だけっぽいのでココに hoge ディレクトリ作って hoge.php を作ればいいのかな.(search() メソッドの第三引数で拡張子指定しててデフォルトが .php だから)

$ mkdir -p fuel/app/views/hoge
$ touch fuel/app/views/hoge/hoge.php

エラー消えた終わり.

## メモ


上の dir 各ディレクトリ探してみる

$ find -name config -o -regex ".*config/development" -o -name views -type d
./fuel/core/classes/config
./fuel/core/config
./fuel/core/views
./fuel/packages/oil/views
./fuel/packages/oil/views/scaffolding/orm/views
./fuel/packages/oil/views/scaffolding/crud/views
./fuel/packages/oil/views/admin/orm/views
./fuel/packages/oil/views/admin/crud/views
./fuel/packages/auth/config
./fuel/packages/parser/config
./fuel/packages/email/config
./fuel/app/config
./fuel/app/config/development
./fuel/app/views
./.git/config