-2

我试图在一个看起来像这样的 url 中传递多个参数......

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

...到控制器中看起来像这样的函数...

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();
    }
}
}

但似乎只有第一个参数成功通过。不知道在这里复制和粘贴什么,但这里是 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.');
}

提前致谢!

4

1 回答 1

-1

从您的动作控制器调用$this->getRequest()->getParams()并检查两个参数是否都存在。

如果否,则问题出在您的路由上。

如果是,则问题在于将参​​数传递给您的控制器方法lessonDetails

还有,lessondetailsAction不见了。(如果您访问您发布的网址,这将是调用的方法)

于 2013-04-15T16:03:38.923 回答