這是我的功能,它可以幫助我生成鏈接。所以在這裏構造我從數據庫中獲取數據。現在我想從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