Php kohana 3使用get创建路线
这与路由有关。因此,对于通过url获取参数,基本上是按照设置的路由格式将数据传递到url 这是使用链接。我创建了路由,将数据传递到url中,并使用request方法获取用于控制器的参数。比如Php kohana 3使用get创建路线,php,kohana,Php,Kohana,这与路由有关。因此,对于通过url获取参数,基本上是按照设置的路由格式将数据传递到url 这是使用链接。我创建了路由,将数据传递到url中,并使用request方法获取用于控制器的参数。比如URL::site(“site/$color/$size”) 如果我正在通过表单提交构建url呢?例如,如果我想创建一个基本搜索查询 当我通过get方法提交表单时,如何使表单提交看起来像这个search/orange/large而不是这个search.php?color=orange&size=large。通
URL::site(“site/$color/$size”)
如果我正在通过表单提交构建url呢?例如,如果我想创建一个基本搜索查询
当我通过get方法提交表单时,如何使表单提交看起来像这个search/orange/large
而不是这个search.php?color=orange&size=large
。通过,将提交的信息作为URL参数。如果您特别希望以类似site/$color/$size
的URL结尾,可以使用
一个局部示例,来自我的一个站点上的控制器(页面上有一个名为clear\u cache\u button
)的提交按钮):
您可以使用(v3.3)或(3.1、3.2)手动设置路由参数。您可以这样做
public function action_index()
{
// this will only be executed if you submmitted a form in your page
if(Arr::get($_POST,'search')){
$errors = '';
$data = Arr::extract($_POST,array('color','size'));
// you can now access data through the $data array:
// $data['color'], $data['size']
// perform validations here
if($data['color']=='') $error = 'Color is required';
elseif($data['size']=='') $error = 'Size is required';
if($error==''){
$this->request->redirect('search/'.$data['color'].'/'.$data['size']);
}
}
// load your search page view here
echo 'this is the search page';
}
希望这对您有所帮助。当从路由创建链接时,我更喜欢使用
Route::get()->uri())
,在本例中,这可能类似于Route::get('fruits')->uri(数组('color'=>$color,'size'=>$size))
。此方法的优点是,当路由更改时,链接会自动更改(在您的版本中,更改路由后必须手动更改每个链接)
public function action_index()
{
// this will only be executed if you submmitted a form in your page
if(Arr::get($_POST,'search')){
$errors = '';
$data = Arr::extract($_POST,array('color','size'));
// you can now access data through the $data array:
// $data['color'], $data['size']
// perform validations here
if($data['color']=='') $error = 'Color is required';
elseif($data['size']=='') $error = 'Size is required';
if($error==''){
$this->request->redirect('search/'.$data['color'].'/'.$data['size']);
}
}
// load your search page view here
echo 'this is the search page';
}