CodeIgniter Forums
Anchor function in v3 throws an error if uri is an array - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Development (https://forum.codeigniter.com/forumdisplay.php?fid=6)
+--- Forum: Issues (https://forum.codeigniter.com/forumdisplay.php?fid=19)
+--- Thread: Anchor function in v3 throws an error if uri is an array (/showthread.php?tid=61352)



Anchor function in v3 throws an error if uri is an array - lenny - 04-10-2015

Hello team,

this error can easily be fixed in url_helper.php (around line 160) by adding brackets around the preg_match expression like this

Code:
$site_url = is_array($uri)
           ? site_url($uri)
           : ( preg_match('#^(\w+:)?//#i', $uri) ? $uri : site_url($uri) );


Thank you
Lenny


RE: Anchor function in v3 throws an error if uri is an array - CroNiX - 04-10-2015

But the docs say that $uri should be a string, so you shouldn't be passing an array:

http://www.codeigniter.com/user_guide/helpers/url_helper.html#anchor
Quote:anchor($uri = '', $title = '', $attributes = '')

Parameters:
$uri (string) – URI string
$title (string) – Anchor title
$attributes (mixed) – HTML attributes



RE: Anchor function in v3 throws an error if uri is an array - lenny - 04-10-2015

@cronix:  This is not correct. Take a closer look at the docs please. Above your quote it says that segments can be an array too. This does not work in v3 but it worked in v2. From the docs:


Code:
The first parameter can contain any segments you wish appended to the URL. As with the site_url() function above, segments can be a string or an array.



RE: Anchor function in v3 throws an error if uri is an array - alkarim - 04-21-2015

Thanx for the piece of advice (y)


RE: Anchor function in v3 throws an error if uri is an array - Narf - 04-21-2015

https://github.com/bcit-ci/CodeIgniter/issues/3761