从管理页面重定向到前端的postAction

时间:2012-09-04 14:32:07

标签: php magento redirect magento-1.7

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

我需要从我的模型php文件调用第三方模块(VideoTestimonials from aheadWorks)上的postAction函数,以便重用所有代码来获取所需的功能,并避免将来的错误,如果我只是复制代码和随意修改。

previous question上我指出,我想,正确的方向是使用setRedirect来实现这一目标。这是我在我的php模型文件中使用的代码,试图重定向到前端的postAction:

<?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。有什么问题?

我正在调查此SO question/answerthis post on the Magento forum,但无法让我清楚自己。第二个是来自事件观察者的重定向,我不知道它是否可以提供帮助。

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

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}

1 个答案:

答案 0 :(得分:3)

你使用getUrl和getBaseUrl并且它是一样的,你可以使用这段代码:

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

但你已经在课堂上扩展了Mage_Adminhtml_Controller_Action。这是最好的方式。如果不是控制器,那么你不应该重定向。