【发布时间】:2013-04-15 15:54:31
【问题描述】:
我正在尝试在一个看起来像这样的 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.');
}
提前致谢!
【问题讨论】:
-
...您的问题是什么?什么没有按预期工作?你用的是什么 MVC 框架?
-
向我们展示您的路由代码。
-
基于
htaccess,看起来您正在使用 Zend Framework。这是您的routing的问题,而不是您的.htaccess。 -
糟糕,抱歉。使用上面的代码,只有第一个参数成功传递给函数。
-
没错,为了能够帮助您,我们需要查看您定义的路线。
标签: php url-routing