0

こんにちは、私は zend フレームワークを初めて使用します。ユーザーが画像を編集して画像内にテキストを挿入できるアプリを作成したので、personalmug アプリケーションを実装して zend フレームワークを学習することにしました。

アプリをホストされたサーバーのサブドメインにアップロードしましたが、何らかの理由でアプリケーションが localhost のように動作しません。ローカルホストでは正常に動作していますが、ホストされたサーバーでは何が問題なのかわかりませんが、ajax の成功後にローカルホストでリダイレクトすることについていくつか質問があります。

問題を以下に示します。

質問1。

  1. ホームページを開いてカスタマイズボタンをクリックすると、4 つの入力フィールドがあるフォームを含むモデルが表示されます。4 行を入力してプレビューボタンをクリックすると、コントローラ personalmug が呼び出され、アクションはプレビューです、プレビュー アクションは public/img/ フォルダーにある既存の画像から画像を作成しますが、現在はフォルダー public/img/image_uri に画像を作成しておらず、応答は空白のページであり、firebug では html メッセージ「ページをリロードしてソースを取得する」です。ページをリロードすると、画像がなく、画像がホストされたサーバーの public/img/image_uri フォルダーになく、セッションが作成されない場合、プレビュー アクションに問題があると思います。しかし、私がどこにいるのかわかりません。4日間からグーグルで検索しようとしましたが、成功しませんでした。

同じことがローカルホストで機能しています。

質問番号 2

  1. preview.phtmlページの保存ボタンをクリックした後にページをリダイレクトしたいのですが、コントローラーに保存アクションがあり、localhost mysqlデータベースにデータを保存します。リダイレクトしていますが、 firbug でのみ、実際のページはリダイレクトせず、ajax success でアラートを使用しようとしましたが、メッセージが表示されないので使用できません。

助けてください、事前に感謝します。コードを修正していただければ幸いです。およびいくつかのコード サンプル。再度、感謝します。

索引.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);
    }
}
4

1 に答える 1

1

フレームワークよりもはるかに低いレベルでエラーが発生していると思います。エラーの詳細については、Apache の「error.log」を参照してください。何か見つけたら教えてください。

于 2014-10-18T08:09:56.923 に答える