2012-02-04 3 views
3

JQMでケーキサイトをコーディングしようとしていますが、リンクをクリックするたびに "Undefined"という単語だけが表示されます。CakePHP - jQuery Mobileが "Undefined"という単語を含む空のページを返す

ソースを調べると、この単語を含むdata-role = "page"という新しいdivがあり、元のページの元のコンテンツはそのまま残っていることがわかります。

<!DOCTYPE html> 
<html lang="en"> 
    <head> 
     <meta charset="utf-8" /> 
     <title><?php echo (isset($title_for_layout)) ? $title_for_layout : 'My default title';?></title> 
     <meta name="viewport" content="width=device-width, initial-scale=1"> 
     <?php 
      // javascript 
      $javascripts = array(
        'jquery', 
        'jquery.mobile-1.0.min.js', 
       ); 
      echo $this->Html->script($javascripts); 
      // css 
      $css = array('jquery.mobile-1.0.css','jquery.mobile.structure-1.0.css','themes/mobires.css'); 
      echo $this->Html->css($css) . "\n\t"; 
     ?> 
    </head> 
    <body> 
     <div data-role="page"> 
      <?php echo $this->Session->flash(); ?> 
      <div data-role="header"> 
       <h1> 
        <?php echo (isset($title_for_layout)) ? $title_for_layout : 'My default title';?> 
       </h1> 
       <div data-role="navbar"> 
        <ul> 
         <li><?php echo $this->Html->link('Home',array('controller'=>'pages','action'=>'display','home'))?></li> 
         <li><?php echo $this->Html->link('Contact',array('controller'=>'pages','action'=>'display','contact'))?></li> 
        </ul> 
       </div><!-- /navbar --> 
      </div><!-- /header --> 
      <div data-role="content"> 
       <?php 
        echo $this->Session->flash(); 
        echo $content_for_layout; 
       ?> 
      </div> 
      <!-- start footer --> 
       <div data-role="footer"> 
        &copy; 2012<?php if (date("Y") > 2012) { echo '-' . date("Y"); } ?> Mobires. All Rights Reserved. 
        <br /> 
        &nbsp; 
        <?php echo $this->Html->link('Privacy Policy',array('controller'=>'pages','action'=>'display','privacy'))?> 
        &nbsp; 
        <?php echo $this->Html->link('Terms & Conditions',array('controller'=>'pages','action'=>'display','terms'))?> 

       </div> 
     </div><!-- /page --> 
     <?php echo $this->Js->writebuffer(); ?> 
    </body> 
</html> 

と私home.ctpはそれで単語「test」を持っている:

これは、モバイルビューのための私のレイアウトです。 Ajaxの読み込みをテストする方法として、フッターのボタンをクリックしようとしています。

答えて

2

jquery mobileとcakephpを統合したい場合は、私の意見ではこれが最良の解決策です。また、cakephp 2.xの欠けている空のページを解決します。また、cakephpコントローラでビューファイル(レンダーファイル)の名前を取得する方法の例をInflector :: underscore($ this-> action)と表示することもできます。

public function beforeFilter() { 
$this->isMobile = false; 
     if ($this->RequestHandler->isMobile()) { 

      // required for CakePHP 2.2.2 
      $viewDir = App::path('View'); 
      // returns an array 
      /* 
      * array(
      *  (int) 0 => '/var/www/maps-cakephp2/app/View/' 
      *) 
      */ 
      //path to your folder for mobile views . You must modify these lines that you want 
      //in my case I have views in folders in to /app/view/mobile and here users folder etc. 
      $mobileView = $viewDir[0] . 
        'mobile' . DS . $this->name . DS; 
      $mobileViewFile = $mobileView . 
        Inflector::underscore($this->action) . '.ctp'; 

      if (file_exists($mobileViewFile)) { 
       $this->isMobile = true; 
       $this->viewPath = 'mobile' . DS . $this->name; 

      } 

    } 
} 

public function beforeRender() { 
    if ($this->isMobile == true) { 
     $this->autorender = true; 
     //app/View/Layouts/mobile.ctp 
     $this->layout = 'mobile'; 
    } 
} 
+0

することができますcakephpのビューに新しいテーマ機能を使用する – Martin

1

ああ、JQMは完全にフォーマットされたJQMレスポンスを期待しているので、コンテンツだけでなく、ページ全体を返す必要があります。

+0

こんにちはAndy。私は同じ問題を抱えています...あなたはCakePHPでどのように完全にフォーマットされたJQM応答を得ましたか? – hasentopf

+0

私はここで解決策を見つけました:http://stackoverflow.com/questions/6385714/cakephp-ajax-layout – hasentopf

+0

$ content_for_layoutに欠けていたJQM応答のビットを 'header'と自分のコンテンツの前と後に出力する 'フッター'要素。どのようにリクエストハンドラを無効にしたのですか? – Andy

関連する問題