将 _remap 与动态 URL 段结合使用
我正在使用 _remap:
function _remap( $method )
{
// $method contains the second segment of your URI
switch( $method )
{
case 'hello':
$this->index();
break;
}
}
我想将 url http://localhost/blog
更改为 http://localhost/blog/hello
我的 CI_Controller 是:
class Blog extends CI_Controller {
function __construct()
{
parent::__construct();
}
function _remap( $method )
{
// $method contains the second segment of your URI
switch( $method )
{
case 'hello':
$this->index();
break;
}
}
/**/
function index()
{
$g_subject = $this->input->get('id', TRUE);
$query = $this->db->get_where('miniblog', array('id' => $g_subject));
foreach ($query->result() as $row)
{
$data = array(
'subject' => $row->subject,
'title' => $row->title,
'image_path' => $row->image_path,
'alt' => $row->alt,
'text' => $row->text,
'date' => $row->date,
);
}
$this->load->view('miniblog/blog', $data);
//add customer size to databe on customer
//$this->customer_size_model->show();
}
function ipv6()
{
$this->load->view('miniblog/ipv6');
}
}
我怎样才能将此用于任何动态 ID 并将 $row->subject
替换为 hello?
I'm using _remap:
function _remap( $method )
{
// $method contains the second segment of your URI
switch( $method )
{
case 'hello':
$this->index();
break;
}
}
I want to change the url http://localhost/blog
to http://localhost/blog/hello
my CI_Controller is:
class Blog extends CI_Controller {
function __construct()
{
parent::__construct();
}
function _remap( $method )
{
// $method contains the second segment of your URI
switch( $method )
{
case 'hello':
$this->index();
break;
}
}
/**/
function index()
{
$g_subject = $this->input->get('id', TRUE);
$query = $this->db->get_where('miniblog', array('id' => $g_subject));
foreach ($query->result() as $row)
{
$data = array(
'subject' => $row->subject,
'title' => $row->title,
'image_path' => $row->image_path,
'alt' => $row->alt,
'text' => $row->text,
'date' => $row->date,
);
}
$this->load->view('miniblog/blog', $data);
//add customer size to databe on customer
//$this->customer_size_model->show();
}
function ipv6()
{
$this->load->view('miniblog/ipv6');
}
}
How can I use this for any dynamic id and replace $row->subject
with hello?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以将其路由到另一个函数并将该方法作为参数传递给该函数,而不是将所有传递的方法路由到索引:
Instead of routing all passed methods to index, you could route it to another function and pass the method as the parameter to that function: