본문 바로가기

dev

[codeigniter] anchor

반응형

anchor()

Creates a standard HTML anchor link based on your local site URL:

<a href="http://example.com">Click Here</a>


The tag has three optional parameters:

anchor(uri segments, text, attributes)


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.


Note: If you are building links that are internal to your application do not include the base URL (http://...). This will be added automatically from the information specified in your config file. Include only the URI segments you wish appended to the URL.

The second segment is the text you would like the link to say. If you leave it blank, the URL will be used.

The third parameter can contain a list of attributes you would like added to the link. The attributes can be a simple string or an associative array.

Here are some examples:

echo anchor('news/local/123', 'My News', 'title="News title"');


Would produce: <a href="http://example.com/index.php/news/local/123" title="News title">My News</a>

echo anchor('news/local/123', 'My News', array('title' => 'The best news!'));

Would produce: <a href="http://example.com/index.php/news/local/123" title="The best news!">My News</a>


anchor_popup()

Nearly identical to the anchor() function except that it opens the URL in a new window. You can specify JavaScript window attributes in the third parameter to control how the window is opened. If the third parameter is not set it will simply open a new window with your own browser settings. Here is an example with attributes:

$atts = array(
'width' => '800',

'height' => '600',
'scrollbars' => 'yes',
'status' => 'yes',
'resizable' => 'yes',
'screenx' => '0',
'screeny' => '0'
);

echo anchor_popup('news/local/123', 'Click Me!', $atts);


Note: The above attributes are the function defaults so you only need to set the ones that are different from what you need. If you want the function to use all of its defaults simply pass an empty array in the third parameter:

echo anchor_popup('news/local/123', 'Click Here to Contact Me');


* A 태그를 CI 함수를 통해 생성




반응형