0

嗨,我是 zend 框架的新手,我创建了一个应用程序,它允许用户编辑图像并在图像中放置一些文本,所以我决定通过实现 personalmug 应用程序来学习 zend 框架,

我已将应用程序上传到托管服务器子域,但由于某种原因,我的应用程序与在 localhost 上的工作方式不同。在本地主机上它工作正常,但在托管服务器上我不知道什么是磨损,但是在 ajax 成功后有一些关于在本地主机上重定向的问题。

下面给出问题。

问题 1。

  1. 当我打开主页并单击自定义按钮时,它将显示一个包含表单的模型,具有四个输入字段,当我输入 4 行并单击预览按钮时,它将调用控制器personalmug 并且动作是预览,预览操作将从 public/img/ 文件夹中的现有图像创建图像,现在它不会将图像创建到文件夹 public/img/image_uri 并且响应是空白页,并且在萤火虫中的 html 消息是“重新加载页面以获取源”。当我重新加载页面时,图像不存在并且图像不在托管服务器上的 public/img/image_uri 文件夹中,并且未创建会话,我认为预览操作存在一些问题。但不知道我在哪里磨损,我试图从 4 天开始用谷歌搜索,但没有成功。

同样的事情也在本地主机上工作。

问题 2

  1. 我想在单击 preview.phtml 页面上的保存按钮后重定向页面,现在我在控制器中有一个保存操作,它将数据保存在 localhost mysql 数据库中,它正在重定向但仅在 firbug 中,实际页面是不重定向,我尝试在 ajax 成功中使用警报,但没有使用它不显示消息。

请提前帮助和感谢。我将不胜感激我的代码更正。和一些代码示例。再次感谢。

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

个人马克表文件。

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 回答