2014-10-17 26 views
0

嗨,我是新來的zend框架,我已經創建了一個應用程序,它將允許用戶編輯圖像,並在圖像中放置一些文本,所以我已決定學習zend框架,通過實施personalmug應用程序,重新加載頁面獲取錯誤的頁面源,不知道錯在哪裏

我已經上傳應用程序到託管的服務器子域,但由於某種原因,我的應用程序不像在本地主機上一樣工作。在本地主機上它工作正常,但在託管服務器上,我不知道什麼是worng,但是有一些關於Ajax成功後在localhost上重定向的問題。

這個問題在下面給出。

問題沒有1.

  1. 當我打開主頁,點擊自定義按鈕,它會顯示其中包含形狀的模型,有四個輸入字段,當我在4線類型,然後單擊預覽按鈕,它會調用控制器personalmug並且動作是預覽,預覽動作將從現有圖像創建一個圖像,該圖像位於public/img /文件夾中,現在它不會將圖像創建到public/img/image_uri文件夾中,並且響應是空白頁面,並且在螢火蟲中,html消息是「重新加載頁面以獲得源代碼」。當我重新加載頁面的圖像不存在,圖像不在託管服務器上的public/img/image_uri文件夾中,並且會話未創建,我認爲預覽操作有一些問題。但不知道我在哪裏worng,我試圖谷歌從4天,但沒有成功。

同樣的事情在localhost上工作。

題號2

  1. 我想點擊保存preview.phtml頁面上按鈕後,頁面重定向,現在我有在控制器中的保存操作,這將節省localhost上的MySQL數據庫中的數據,並它是重定向,但只有在firbug,實際頁面不重定向,我試圖在ajax成功使用警報,但沒有使用它不顯示消息。

請幫助,並提前致謝。我將不勝感激我的代碼更正。和一些代碼示例。再次感謝。

Index.phtml

<div class="row top-buffer"> 
    <div class="span9"> 
     <div class="row"> 
      <div class="col-md-4"><img src='<?php echo $this->basePath('img/whitemug toxic fox.jpg') ?>'class="img-responsive"/></div> 
      <div class="col-md-6"> 
       <h3><strong>Personal Mug</strong></h3> 
       <h3><small>Show your amazing coach just how great he is with this No.1 Coach Mug. This mug is a great gift for any occasion, make your gift extra special by personalising it with any name of your choice. This thoughtful gift is guaranteed to impress!</small></h3> 
       <a name="fulldescription">Read Full Description</a> 
       <div class="row top-buffer"> 
        <div class="col-md-8"> 
         <button class="btn btn-success btn-lg btn-block" data-toggle="modal" data-target="#myModal">Customize</button> 
        </div> 
       </div> 
       <div class="row top-buffer"> 
        <ul> 
         <li> 
          The mug has space for a maximum of 48 characters, over a maximum of 4 lines. 
         </li> 
         <li> 
          Free Delivery when you spend over £40 
         </li> 
         <li> 
          Guaranteed Fast, Secure Shipping 
         </li> 
        </ul> 
       </div> 

      </div> 
     </div> 
    </div> 
</div> 
<div class="row"> 
    <div class="col-md-6 "> 
     <h3><strong>Personal Mug</strong></h3> 
     <h4><small>Is your coach simply the best?</small></h4> 
     <h4>Reward them with this amazing No.1 Coach Mug. This mug features a fabulous award design with the message COACH (any name) no.1! Make this thoughtful gift extra special and personal by adding your coaches name!</h4> 

    </div> 

    <div class="col-md-6 "> 
     <?php foreach($personalmugs as $personalmug) : ?> 
     <div class="col-md-3 top-buffer"> <a href="#"> 
       <img src="<?php echo $this->basePath($this->escapeHtml($personalmug->image_uri)); ?>" class="img-thumbnail img-responsive"> 
      </a> 
     </div> 
     <?php endforeach; ?> 
    </div> 
</div> 
<!-- Modal --> 
<div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true"> 
    <div class="modal-dialog"> 
     <div class="modal-content"> 
      <div class="modal-header"> 
       <button type="button" class="close" data-dismiss="modal"><span aria-hidden="true">&times;</span><span class="sr-only">Close</span></button> 
       <h4 class="modal-title" id="myModalLabel">Submit text</h4> 
      </div> 
      <div class="modal-body"> 
       <form class="form-horizontal" action="personal-mug/preview" role="form" method="POST"> 
        <div class="form-group"> 
         <label for="inputText" class="col-sm-2 control-label">Text</label> 
         <div class="col-sm-10"> 
          <input class="form-control" type="text" name="mugtext1" maxlength="12" placeholder=Line1 pattern="^[a-zA-Z0-9\s]+" title="Only Alphabets and Numbers" min="1" max="12" required> 
          <input class="form-control" type="text" name="mugtext2" maxlength="12" placeholder=Line2 pattern="^[a-zA-Z0-9\s]+" title="Only Alphabets and Numbers" min="1" max="12" required> 
          <input class="form-control" type="text" name="mugtext3" maxlength="12" placeholder=Line3 pattern="^[a-zA-Z0-9\s]+" title="Only Alphabets and Numbers" min="1" max="12" required> 
          <input class="form-control" type="text" name="mugtext4" maxlength="12" placeholder=Line4 pattern="^[a-zA-Z0-9\s]+" title="Only Alphabets and Numbers" min="1" max="12" required> 

         </div> 
        </div> 
        <div class="form-group"> 
         <div class="col-sm-offset-2 col-sm-10"> 
          <button name="submit" value="submit" type="submit" class="btn btn-default">Preview</button> 
         </div> 
        </div> 
       </form> 
      </div> 
     </div> 
    </div> 
</div> 

預覽PHTML文件的代碼。

<div class="row top-buffer"> 
    <div class="span9"> 
     <div class="row"> 
      <div class="col-md-4"><img id="mug1" name="mug1" src=' 
       <?php 
       if(isset($_SESSION['preview_image_id']) && !empty($_SESSION['preview_image_id'])){ 
        $ID = $_SESSION['preview_image_id']; 
        echo $this->basePath("img/image_uri/$ID.jpg"); 
       } ?>'class="img-responsive"/></div> 
      <div class="col-md-6"> 
       <h3><strong>Personal Mug</strong></h3> 
       <h3><small>Show your amazing coach just how great he is with this No.1 Coach Mug. This mug is a great gift for any occasion, make your gift extra special by personalising it with any name of your choice. This thoughtful gift is guaranteed to impress!</small></h3> 

       <div class="row top-buffer"> 
        <div class="col-md-8"> 

         <a id ="buttonSave" class="btn btn-success btn-lg btn-block">Save</a> 
         <a class="btn btn-success btn-lg btn-block" href="<?php echo $this->url('personal-mug', array('action'=>'add'));?>">Edit</a> 
        </div> 
       </div> 
       <div class="row top-buffer"> 
        <ul> 
         <li> 
          The mug has space for a maximum of 48 characters, over a maximum of 4 lines. 
         </li> 
         <li> 
          Free Delivery when you spend over £40 
         </li> 
         <li> 
          Guaranteed Fast, Secure Shipping 
         </li> 
        </ul> 
       </div> 

      </div> 
     </div> 
    </div> 
</div> 
<script> 
    $('#buttonSave').click(function(){ 
      var image_uri = $("#mug1").attr("src"); 
      $.ajax({ 
        type: 'POST', 
        dataType: 'json', 
        url: 'http://toxicfox.com/personal-mug/add', 
        async: false, 

        // you can use an object here 
        data: { image_uri: image_uri}, 
        success: function(json) { 
         console.log(json.image_uri); 
        } 
       }); 
      // you might need to do this, to prevent anchors from following 
      // or form controls from submitting 

     }); 
</script> 

控制器。

namespace PersonalMug\Controller; 

use Zend\Mvc\Controller\AbstractActionController; 
use Zend\View\Model\ViewModel; 
use PersonalMug\Model\PersonalMug;   
use PersonalMug\Form\PersonalMugForm;  


class PersonalMugController extends AbstractActionController{ 
protected $personalmugTable; 

public function getPersonalMugTable(){ 
    if(!$this->personalmugTable){ 
     $sm = $this->getServiceLocator(); 
     $this->personalmugTable = $sm->get('PersonalMug\Model\PersonalMugTable'); 
    } 
    return $this->personalmugTable; 
} 

public function indexAction(){ 
    return new ViewModel(
     array(
      'personalmugs' => $this->getPersonalMugTable()->fetchAll(), 
     )); 
} 
public function addAction(){  

    $data['image_uri'] = $this->getRequest()->getPost('image_uri'); 
    $personalmug = new PersonalMug(); 
    $personalmug->exchangeArray($data); 
    $this->getPersonalMugTable()->save($personalmug); 
    return $this->redirect()->toRoute('personal-mug'); 
} 
public function previewAction(){ 
    if(isset($_POST['submit'])){ 
     session_start(); 
     $ID = uniqid(); 
     $_SESSION['preview_image_id'] = $ID; 
     $text1 = htmlspecialchars($_POST['mugtext1']); 
     $text2 = htmlspecialchars($_POST['mugtext2']); 
     $text3 = htmlspecialchars($_POST['mugtext3']); 
     $text4 = htmlspecialchars($_POST['mugtext4']); 
     $this->getPersonalMugTable()->preview($ID,$text1,$text2,$text3,$text4); 
    } 
} 

personalmug表文件。

namespace PersonalMug\Model; 

use Zend\Db\TableGateway\TableGateway; 
use Zned\ServerUrl\Helper; 

class PersonalMugTable{ 
    protected $tableGateway; 

    public function __construct(TableGateway $tableGateway){ 
     $this->tableGateway = $tableGateway; 
    } 

    public function fetchAll(){ 
     $resultSet = $this->tableGateway->select(); 
     return $resultSet; 
    } 

    public function getImage($image_id){ 
     $image_id = (int) $image_id; 
     $rowset = $this->tableGateway->select(array('image_id' => $image_id)); 
     $row = $rowset->current(); 
     if(!$row){ 
      throw new \Exception("Could not find row $image_id"); 
     } 
     return $row; 
    } 

    public function save(PersonalMug $personalmug){ 
     $data = array(
      'image_id' => $personalmug->image_id, 
      'image_uri' => $personalmug->image_uri, 
     ); 

     $image_id = (int) $personalmug->image_id; 
     if($image_id == 0){ 
      $this->tableGateway->insert($data); 
     }else{ 
      if($this->getImage($image_id)){ 
       $this->tableGateway->update($data, array('image_id' => $image_id)); 
      }else{ 
       throw new \Exception('Mug id does not exist'); 
      } 
     } 
    } 

    public function deleteAlbum($image_id){ 
     $this->tableGateway->delete(array('image_id' => (int) $image_id)); 
    } 

    public function preview($ID,$text1,$text2,$text3,$text4){ 
     strtoupper($text1); 
     strtoupper($text2); 
     strtoupper($text3); 
     strtoupper($text4); 
     // load the image from the file specified: 

     $im = imagecreatefromjpeg('public/img/whitemug%20toxic%20fox.jpg'); 
     // if there's an error, stop processing the page: 
     if(!$im){ 
      die(""); 
     } 

     // define some colours to use with the image 
     $black = imagecolorallocate($im, 0, 0, 0); 


     // now we want to write in the centre of the rectangle: 
     $font ="public/fonts/arial.ttf"; // store the int ID of the system font we're using in $font 
     // store the text we're going to write in $text 

     // finally, write the string: 

     imagettftext($im,60,0,260,460,$black,$font,$text1); 
     imagettftext($im,60,0,260,560,$black,$font,$text2); 
     imagettftext($im,60,0,260,660,$black,$font,$text3); 
     imagettftext($im,60,0,260,760,$black,$font,$text4); 

     imagejpeg($im, "public/img/image_uri/$ID.jpg"); 

     // tidy up 
     imagedestroy($im); 
    } 
} 

回答

1

我覺得你的錯誤比框架要低得多。嘗試查看Apache「error.log」以獲取有關該錯誤的更多詳細信息。如果您發現任何問題,請告訴我。

+0

是的,這是因爲createimafeform網址,圖像有錯誤,我無法從URL創建圖像,請指導我從url創建圖像並將其保存到文件。實際上我想要創建從託管服務器上的jpeg,這就是爲什麼銀行是空白的。你能幫我從url創建圖片嗎? – Muhabutti 2014-10-18 22:05:29

+0

您是否嘗試使用絕對路徑來存檔文件?具體在這些地方:$ im = imagecreatefromjpeg('public/img/whitemug%20toxic%20fox.jpg'); $ font =「public/fonts/arial.ttf」; imagejpeg($ im,「public/img/image_uri/$ ID.jpg」); – 2014-10-19 11:39:09

+0

是的,謝謝兄弟,多數民衆贊成我現在想要它的工作感謝soooooooooo。 – Muhabutti 2014-10-20 01:43:46