【发布时间】:2012-09-04 14:32:07
【问题描述】:
编辑后的代码:现在我没有收到 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/answer 和this 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}
【问题讨论】:
-
看起来您正在重定向到一个不存在的页面。在这种情况下,url 不会映射到控制器,以便应用程序可以正确处理您的请求。如果打印出 Mage::getBaseUrl().'vidtest/youtube/post' 的内容,那么完整的 URL 是什么?如果您导航到该 URL,您是否会收到 404(未找到文件)或某些应用程序错误?
-
hmmm...尝试了
echo来查看$actionUrl,但它不正确:http://127.0.0.1/magento/index.php/http:/index/127.0.0.1/magento/index.php/vidtest/youtube/。似乎它搞砸了getbaseurl和其他东西。我当然会得到404 Error
标签: php magento redirect magento-1.7