从管理页面重定向到前端的postAction [英] redirecting from admin page to a postAction on frontend

查看:603
本文介绍了从管理页面重定向到前端的postAction的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

编辑后的代码:现在,我没有收到404错误,但另一方面,数据库或异常日志上没有添加任何内容.

Edited code: now I'm not receiving the 404 Error but on the other hand there is nothing added on the database or on exception logs.

我需要从模型php文件中调用第三方模块上的postAction函数(

I need to call from my model php file a postAction function on a third part module (VideoTestimonials from aheadWorks) in order to reuse all their code to get the needed functionalities and avoid future bugs if I just copied the code and modified at will.

在一个上一个问题中,我指出了正确的方向通过使用setRedirect来实现此目标.这是我在php模型文件上使用的代码,尝试将其重定向到前端的postAction:

On a previous question I was pointed on the, I guess, right direction to accomplish this goal by using setRedirect. Here is the code I'm using on my php model file to try to redirect to the postAction on the frontend:

<?php
class Dts_Videotestimonials_Model_SearchVideo extends Mage_Core_Model_Abstract
{

    function printVideoEntry($videoEntry, $_product, $tabs = "")
    {
        # get user data
        $user = Mage::getSingleton('admin/session');
        $userName = $user->getUser()->getFirstname();
        $userEmail = $user->getUser()->getEmail();
        $data = array(
            "ProductId" => $_product->getId(),
                        "AuthorEmail" => $userEmail,
                        "AuthorName" => $userName,
                        "VideoLink" => $videoEntry->getVideoWatchPageUrl(),
                        "VideoType"  => "link",
                        "Title" => $videoEntry->getVideoTitle(),
                        "Comment" => "this is a comment"
        );
        $actionUrl = Mage::getUrl('vidtest/youtube/post', $data);
        Mage::app()->getResponse()->setRedirect($actionUrl);
    }
}

所有修改到这里都可以了,一步一步地(在@Francesco的帮助下),我到了这一点.但是,当我拨打电话时,我收到的是404 Error.怎么了?

All the modifications to get here where ok, step by step (with help of @Francesco) I got to this point. But when I make this call I'm receiving a 404 Error. What is wrong?

我一直在调查 SO问题/答案在Magento论坛上的帖子,但我不清楚.第二个是事件观察者的重定向,我不知道它是否可以帮助您.

I was looking into this SO question/answer and this post on the Magento forum but can't make my self clear. The second one is a redirect from an event Observer, I do not know exactly if it can help.

这是此错误的完整异常日志:

Here is the full exception log on this error:

2012-09-04T14:25:17+00:00 ERR (3): 
exception 'Zend_Controller_Response_Exception' with message 'Invalid HTTP response code' in C:\wamp\www\magento\lib\Zend\Controller\Response\Abstract.php:286
Stack trace:
#0 C:\wamp\www\magento\lib\Zend\Controller\Response\Abstract.php(150): Zend_Controller_Response_Abstract->setHttpResponseCode(Array)
#1 C:\wamp\www\magento\app\code\core\Mage\Core\Controller\Response\Http.php(106): Zend_Controller_Response_Abstract->setRedirect('http://127.0.0....', Array)
#2 C:\wamp\www\magento\app\code\local\Dts\Videotestimonials\Model\SearchVideo.php(64): Mage_Core_Controller_Response_Http->setRedirect('http://127.0.0....', Array)
#3 C:\wamp\www\magento\app\code\local\Dts\Videotestimonials\Model\SearchVideo.php(198): Dts_Videotestimonials_Model_SearchVideo->printVideoEntry(Object(Zend_Gdata_YouTube_VideoEntry), Object(Mage_Catalog_Model_Product))
#4 C:\wamp\www\magento\app\code\local\Dts\Videotestimonials\Model\SearchVideo.php(244): Dts_Videotestimonials_Model_SearchVideo->printVideoFeed(Object(Zend_Gdata_YouTube_VideoFeed), Object(Mage_Catalog_Model_Product), 'Search results ...')
#5 C:\wamp\www\magento\app\code\local\Dts\Videotestimonials\controllers\Adminhtml\VideotestimonialsbackendController.php(28): Dts_Videotestimonials_Model_SearchVideo->searchAndPrint('s')
#6 C:\wamp\www\magento\app\code\core\Mage\Core\Controller\Varien\Action.php(419): Dts_Videotestimonials_Adminhtml_VideotestimonialsbackendController->postAction()
#7 C:\wamp\www\magento\app\code\core\Mage\Core\Controller\Varien\Router\Standard.php(250): Mage_Core_Controller_Varien_Action->dispatch('post')
#8 C:\wamp\www\magento\app\code\core\Mage\Core\Controller\Varien\Front.php(176): Mage_Core_Controller_Varien_Router_Standard->match(Object(Mage_Core_Controller_Request_Http))
#9 C:\wamp\www\magento\app\code\core\Mage\Core\Model\App.php(354): Mage_Core_Controller_Varien_Front->dispatch()
#10 C:\wamp\www\magento\app\Mage.php(683): Mage_Core_Model_App->run(Array)
#11 C:\wamp\www\magento\index.php(87): Mage::run('', 'store')
#12 {main}

推荐答案

您使用getUrl和getBaseUrl是同一件事,您可以使用以下代码:

you using getUrl and getBaseUrl and it's the same thing, you can use this code:

$this->_redirect('module/controller/action','parameters');

但是您已经在您的课程上扩展了Mage_Adminhtml_Controller_Action.这是最好的方法.如果不是控制器,则您不应执行此重定向.

but u have extends Mage_Adminhtml_Controller_Action on your class. its the best way. if isn't a controller so u shouldn't do this redirect.

这篇关于从管理页面重定向到前端的postAction的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆