duanqiu2064 2013-04-15 15:54
浏览 93

通过MVC框架中的URL传递多个参数

I'm trying to pass multiple parameters in a url that looks like this...

http://somedomain.com/lessons/lessondetails/5/3

... to a function in the controller that looks like this ...

class LessonsController extends Controller

{
public function lessonDetails($studentId, $editRow=NULL)
{
    try {
        $studentData = new StudentsModel();
        $student = $studentData->getStudentById((int)$studentId);
        $lessons = $studentData->getLessonsByStudentId((int)$studentId);

        if ($lessons)
        {
            $this->_view->set('lessons', $lessons);

        } 
        else
        {
            $this->_view->set('noLessons', 'There are no lessons currently scheduled.');
        }
        $this->_view->set('title', $student['first_name']);
        $this->_view->set('student', $student);

        return $this->_view->output();

    } catch (Exception $e) {
        echo "Application error: " . $e->getMessage();
    }
}
}

But only the first parameter seems to pass successfully. Not sure what to copy and paste here but here's the bootstrap.php...

$controller = "students";
$action = "index";
$query = null;

if (isset($_GET['load']))
{
    $params = array();
    $params = explode("/", $_GET['load']);

    $controller = ucwords($params[0]);

    if (isset($params[1]) && !empty($params[1]))
    {
            $action = $params[1];
    }

    if (isset($params[2]) && !empty($params[2]))
    {
            $query = $params[2];
    }
}

$modelName = $controller;
$controller .= 'Controller';
$load = new $controller($modelName, $action);

if (method_exists($load, $action))
{
    $load->{$action}($query);
}
else
{
    die('Invalid method. Please check the URL.');
}

Thanks in advance!

  • 写回答

1条回答 默认 最新

  • dongshaidu2456 2013-04-15 16:03
    关注

    Call $this->getRequest()->getParams() from your action controller and check if both parameters are there.

    If NO, the problem lies with your routing.

    If YES, the problem lies with passing the parameters to your controller method lessonDetails.

    Also, lessondetailsAction is missing. (this will be the method called if you visit the url you posted)

    评论

报告相同问题?

悬赏问题

  • ¥15 drone 推送镜像时候 purge: true 推送完毕后没有删除对应的镜像,手动拷贝到服务器执行结果正确在样才能让指令自动执行成功删除对应镜像,如何解决?
  • ¥15 求daily translation(DT)偏差订正方法的代码
  • ¥15 js调用html页面需要隐藏某个按钮
  • ¥15 ads仿真结果在圆图上是怎么读数的
  • ¥20 Cotex M3的调试和程序执行方式是什么样的?
  • ¥20 java项目连接sqlserver时报ssl相关错误
  • ¥15 一道python难题3
  • ¥15 牛顿斯科特系数表表示
  • ¥15 arduino 步进电机
  • ¥20 程序进入HardFault_Handler