2010-12-28 18 views
2

静的コンテンツをZendフレームワークで表示しようとしています。静的コンテンツがZend FWで表示されない

http://square.localhost/content/servicesにアクセスすると、エラーメッセージが表示されます。

この問題を解決する方法を教えてもらえますか?

ありがとうございます。

のapplication.ini

.... 
.... 
resources.layout.layoutPath = APPLICATION_PATH "/layouts" 
resources.layout.layout = "master" 
resources.router.routes.home.route = /home 
resources.router.routes.home.defaults.module = default   
resources.router.routes.home.defaults.controller = index 
resources.router.routes.home.defaults.action = index 
resources.router.routes.static-content.route = /content/:page    
resources.router.routes.static-content.defaults.module = default   
resources.router.routes.static-content.defaults.controller = static-content 
resources.router.routes.static-content.defaults.action = display 

アプリケーション/モジュール/デフォルト/コントローラ/ StaticContentController.php

class StaticContentController extends Zend_Controller_Action 
{ 
    public function init() 
    { 
    } 

    // display static views 
    public function displayAction() 
    { 
     $page = $this->getRequest()->getParam('page'); 
      if (file_exists($this->view->getScriptPath(null) . "/" . $this->getRequest()->getControllerName() . "/$page." . $this->viewSuffix)) { 
     $this->render($page); 
     } else { 
     throw new Zend_Controller_Action_Exception('Page not found', 404); 
     } 
    }  
} 

アプリケーション/モジュール/デフォルト/ビュー/スクリプト/静的コンテンツ/ services.phtml

some html 
... 
... 

エラーメッセージ

An error occurred 
Page not found 
Exception information: 

Message: Page not found 
Stack trace: 

#0 /var/www/square/library/Zend/Controller/Action.php(513): StaticContentController->displayAction() 
#1 /var/www/square/library/Zend/Controller/Dispatcher/Standard.php(295): Zend_Controller_Action->dispatch('displayAction') 
#2 /var/www/square/library/Zend/Controller/Front.php(954): Zend_Controller_Dispatcher_Standard->dispatch(Object(Zend_Controller_Request_Http), Object(Zend_Controller_Response_Http)) 
#3 /var/www/square/library/Zend/Application/Bootstrap/Bootstrap.php(97): Zend_Controller_Front->dispatch() 
#4 /var/www/square/library/Zend/Application.php(366): Zend_Application_Bootstrap_Bootstrap->run() 
#5 /var/www/square/public/index.php(26): Zend_Application->run() 
#6 {main} 

Request Parameters: 

array (
    'page' => 'services', 
    'module' => 'default', 
    'controller' => 'static-content', 
    'action' => 'display', 
) 
+0

file_exists(...)はfalseを返しますか? –

+0

@datatoi:あなたが何を意味するか分かりません... – shin

答えて

2

file_exists()行をデバッグします。あなたのビュースクリプトファイルが間違った場所にあるか、ファイルの間違った場所を探しています。私はこのことから構築される実際の文字列のthatsを見て開始します:

$this->view->getScriptPath(null) . "/" . $this->getRequest()->getControllerName() . "/$page." . $this->viewSuffix 
0

は一緒にいくつかのデバッグを作ってみよう:

このようなあなたの行動をしよう、と我々は最後の時間に

をしたとして、あなたの質問を更新します
public function displayAction() 
    { 
     $page = $this->getRequest()->getParam('page'); 
     var_dump($page); 
     var_dump(file_exists($this->view->getScriptPath(null) . "/" . $this->getRequest()->getControllerName() . "/$page." . $this->viewSuffix)); 
     die("the code will stop here"); 
      if (file_exists($this->view->getScriptPath(null) . "/" . $this->getRequest()->getControllerName() . "/$page." . $this->viewSuffix)) { 
     $this->render($page); 
     } else { 
     throw new Zend_Controller_Action_Exception('Page not found', 404); 
     } 
    }  

更新

これは奇妙です...
どうして来る$page = about-us ?? とあなたはそれが$page = services

2つ目falseでなければならない、あなたのケースでhttp://square.localhost/content/services を閲覧しようとしているがabout-us.phtmlページが 存在する名前about-us.phtml と空のページを作成し、エラーが離れて

行くだろうしないことを意味し
+0

遅く返事を申し訳ありません。私は寝なければならなかった。とにかくもう一度感謝します。私はあなたのコードを次のようにしました。 string(8) "about-us" bool(false)ここでコードは終了します – shin

+0

申し訳ありません。私は2ページのサービスとabout-usを持っています。 application/modules/default/views/scripts/static-contentには、services.phtmlとabout-us.phtmlというページがあります。 – shin

+0

あなたは 'var_dump($ this-> view-> getScriptPath(null)。"/"。$ this-> getRequest() - > getControllerName()。"/$ page "を追加しようとすることができますか?$ this-> viewSuffix ); 'それを出力してください。 – tawfekov

1

この「$ this-> view-> getScriptPath()」は、配列を返します。このように使うことができます "$ this-> view-> getScriptPath()[0]"

+0

それです!よくやった。このメソッドは実際に最初の部分を取得するために必要な配列を返します。 +1 – ALH

関連する問題