如何重定向到某个 url 并将值返回给调用者函数?
我正在 PHP 中开发 joomla MVC 组件。 我需要以下功能 1) & 2)在我的组件代码中的 model.php 之一中。
function xyz()
{
//blah blah
//1) I have to redirect
$mainframe->redirect( 'index.php?option=com_abc','');
//2) and also return value to caller function
return $row;
}
我该如何实现这一目标?
谢谢 :)
I am working on a joomla MVC component in PHP.
I need following functionality 1) & 2) in one of model.php in my component code.
function xyz()
{
//blah blah
//1) I have to redirect
$mainframe->redirect( 'index.php?option=com_abc','');
//2) and also return value to caller function
return $row;
}
How do I achieve this ?
Thanks :)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
通常,在 MVC 方法中,模型不应该重定向用户,这是在控制器上完成的。在控制器上,您可以这样做:
这样,用户将在当前控制器的操作完成后重定向,而不是在调用 setRedirect 方法时重定向,
但如果您确实需要在模型上执行此操作,则可以传递控制器作为模型函数的参数,并从那里设置重定向并返回值:
然后,在您的控制器中:
Usually, in the MVC approach, models shouldn't be redirecting the users, that's done on the controllers. On the controller, you can do:
In that way, the user will be redirected after the current controller's action is completed and not exactly when you call the setRedirect method
but if you really need to do it on the model, you can pass the controller as a parameter there to the model's function and set the redirect from there and return the value:
then, in your controller: