I'm developing an app (PHP + CodeIgniter) that has some messages (modal messages) like:
"Invoice #212 generated" or "This invoice is associated with payment #685."
Well, that ID numbers I wanna make a link to redirect user to the respective item (invoice, payment, product, person, whatever...)
So, I thought to develop at server-side, while building messages like:
str="Invoice#212 generated.";
replace(str, "invoice#222", "<a href='invoice/222'>invoice #222</a>")
Of course, using regex or something like that.
Is this the best way? Any suggestion?
Messages are generated inside actions, using global function "set_message" And Messages as "printed" inside header, using function "echo_message"
In PHP you could have something like this (rough generic example):
$string = 'Invoice #212 generated'; // or 'See payment #121'
$string = preg_replace('/(\w+) #(\d+)/', '<a href="/$1/$2">$0</a>', $string);
Pretty flexible if you don't want to change previously generated strings.