我有一个名为staff的模块。因此,我可以将其命名为: test.com/staff,test.com/staff/save
我已经使用过一些路径来使用它,比如,test.com/teacher,test.com/librarian等
我使用$this->uri->segment(1)来获取人员类型。
现在,在保存时,我希望所有内部函数都使用test.com/ staff /save,并从uri段获取人员类型。
但是,当我保存时,当调用保存函数而不是教师或图书馆管理员时,我会得到作为工作人员的uri段。
简而言之,Module name = staff。为教师、图书管理员等添加了路径。
现在,浏览器URL = http://test.com/teacher
保存URL (使用ajax) = http://test.com/staff/save
在保存时,我需要将浏览器片段设置为"teacher“,这样我就可以将其作为类别获取,但我使用$this->uri-> segment (1)获取了"staff”。
如何使其只使用浏览器url链接中的uri段,而不使用函数调用?
发布于 2021-05-23 20:42:07
试试这个:
查看页面:
<?php
$segment= $this->uri->segment(1);
?>
<button onclick ="callNew('<?php echo $segment; ?>')">Click Me</button>
</div>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
<script>
function callNew(segment)
{
var baseUrl = "<?php echo base_url();?>index.php/welcome/test";
$.ajax({
url: baseUrl,
type:"POST",
data:{ segment_uri: segment },
success: function (response)
{
alert(response);
},
error: function()
{
alert("ERror");
}
});
}
</script>控制器:
public function test()
{
$segment_uri= $this->input->post('segment_uri');
echo $segment_uri;
}https://stackoverflow.com/questions/67657856
复制相似问题