【发布时间】:2016-09-27 06:54:02
【问题描述】:
这是我的功能,可帮助我生成链接。所以在这里构造我从数据库中获取数据。现在我想从像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呢? -
它在这里不起作用,因为我将从字符串中替换列名。
标签: php arrays regex string replace