这是我的功能,它可以帮助我生成链接。所以在这里构造我从数据库中获取数据。现在我想从db记录生成链接,如http://localhost/myCrm/my_module/edit/3/1
我知道它将需要字符串替换,但我陷入了如何做到这一点?需要动态替换字符串的参数
function getLinks(array $Links, bool $actions = true)
{
$data = $this->data;
/* $data will look like this.
But it will vary on because this function will be used
over different schema to generate the links */
// $data = ['id'=>'1', 'module_id' => '3', 'item_id' => '1'];
$action = "";
if($actions && $Links)
{
foreach ($Links as $key => $value)
{
$url = "";
// $url = "i need url replaced with the key defined in '{}' from $data[{key}] "
$action .= '<a href="'.$url.'" >'.$value['text'].'</a>';
}
}
}
$Links = [
[
'text' => 'Edit'
'url' => base_url('my_module/edit/{module_id}/{item_id}')
]
];
任何帮助表示赞赏。
那么'str_replace'呢? –
它不会在这里工作,因为我会从字符串中替换列名称。 – user5181531