我只是想知道如何在使用UpStudProf
函数后重定向到StudProfile
。运行UpStudProf
函数后,URL变成了http://localhost/csms/public/index.php/Home/StudProfile
,但它应该是http://localhost/Home/StudProfile
,是否可以删除URL上的Controller名称Home
?
public function StudProfile(){
$crudModel = new Mod_Stud();
$data = [];
$data['user_data'] = $crudModel->orderBy('s_id', 'ASC')->findAll();
$data['title'] = 'SMS | STUDENT PROFILE';
$data['heading'] = 'Welcome to SMS';
$data['main_content'] = 'stud-prof'; // page name
return view('innerpages/template', $data);
}
public function UpStudProf(){
$crudModel = new Mod_Stud();
$s_id = $this->request->getPost('s_id');
$data = array(
's_lrn' => $this->request->getPost('s_lrn'),
's_fname' => $this->request->getPost('s_fname'),
's_mname' => $this->request->getPost('s_mname'),
's_lname' => $this->request->getPost('s_lname'),
);
$crudModel->upStud($data, $s_id);
return redirect()->to('Home/StudProfile'); //return to StudProfile
}
Routes.php
$routes->setDefaultNamespace('App\Controllers');
$routes->setDefaultController('Home');
$routes->setDefaultMethod('index');
$routes->setTranslateURIDashes(false);
$routes->set404Override();
$routes->setAutoRoute(true);
1条答案
按热度按时间p4tfgftt1#
...是否可以删除URL上的控制器名称
Home
?仅使用定义的路线
当没有找到与URI匹配的已定义路由时,系统将尝试将该URI与上述控制器和方法进行匹配。您可以禁用此自动匹配,并将路由限制为仅由您定义的路由,方法是将
setAutoRoute()
选项设置为false
:其次,在禁用自动匹配后,声明您的用户定义路由:应用程序/配置/路由.php
最后:\应用程序\控制器\主页::UpStudProf,
重定向(字符串$route)
参数:$route(string)-要将用户重定向到的反向路由或命名路由。
代替:
使用此选项: