์ด ๋ฌธ์์์๋ CLink ํด๋์ค๋ฅผ ์ฌ์ฉํ์ฌ HTML link ํ๊ทธ๋ฅผ ์์ฑํ๋ ๋ฐฉ๋ฒ์ ๋ํด ์ค๋ช
ํฉ๋๋ค. CLink ํด๋์ค๋ jiny/html ํจํค์ง์ ์ผ๋ถ๋ก, a ํ๊ทธ๋ฅผ ๊ฐ์ฒด ์งํฅ ๋ฐฉ์์ผ๋ก ์์ฑํ๊ณ ๊ด๋ฆฌํ ์ ์๊ฒ ํด์ค๋๋ค.
CLink ํด๋์ค๋ CTag ํด๋์ค๋ฅผ ์์๋ฐ์ HTML์ a ํ๊ทธ๋ฅผ ์ฝ๊ฒ ์์ฑํ๊ณ ๊ด๋ฆฌํ ์ ์๋๋ก ํฉ๋๋ค. CLink ํด๋์ค๋ a ํ๊ทธ์ ๋งํฌ URL, ํ๊ฒ, ํ์ธ ๋ฉ์์ง ๋ฑ์ ์ค์ ํ ์ ์๋ ๋ฉ์๋๋ฅผ ์ ๊ณตํฉ๋๋ค.
CLink ๊ฐ์ฒด๋ ๊ธฐ๋ณธ์ ์ผ๋ก a ํ๊ทธ๋ฅผ ์์ฑํฉ๋๋ค. ์์ฑ์์์ ๋งํฌ ํ
์คํธ์ URL์ ์ด๊ธฐํํ ์ ์์ต๋๋ค:
use html\src\CLink;
$link = new CLink('Click Here', 'https://example.com');
echo $link->toString();์ด ์ฝ๋๋ ๋ค์๊ณผ ๊ฐ์ HTML์ ์ถ๋ ฅํฉ๋๋ค:
<a href="https://example.com">Click Here</a>setHref ๋ฉ์๋ ๋๋ setUrl๋ฉ์๋๋ฅผ ์ฌ์ฉํ์ฌ a ํ๊ทธ์ href ์์ฑ์ ๋งํฌ URL์ ์ค์ ํ ์ ์์ต๋๋ค:
$link = new CLink();
$link->setHref('https://example.com');
$link->addItem('Visit Example');
echo $link->toString();$link = new CLink();
$link->setUrl('https://example.com');
$link->addItem('Visit Example');
echo $link->toString();์ด ์ฝ๋๋ ๋ค์๊ณผ ๊ฐ์ HTML์ ์ถ๋ ฅํฉ๋๋ค:
<a href="https://example.com">Visit Example</a>setTarget ๋ฉ์๋๋ฅผ ์ฌ์ฉํ์ฌ ๋งํฌ๊ฐ ์ด๋ฆฌ๋ ๋ฐฉ์์ ์ค์ ํ ์ ์์ต๋๋ค. ์๋ฅผ ๋ค์ด, ์ ํญ์์ ๋งํฌ๋ฅผ ์ด๋ ค๋ฉด _blank๋ฅผ ์ค์ ํฉ๋๋ค:
$link = new CLink('Open in New Tab', 'https://example.com');
$link->setTarget('_blank');
echo $link->toString();์ด ์ฝ๋๋ ๋ค์๊ณผ ๊ฐ์ HTML์ ์ถ๋ ฅํฉ๋๋ค:
<a href="https://example.com" target="_blank">Open in New Tab</a>addSID ๋ฉ์๋๋ฅผ ์ฌ์ฉํ์ฌ URL์ sid ๋งค๊ฐ๋ณ์๋ฅผ ์ถ๊ฐํ ์ ์์ต๋๋ค. sid ๋งค๊ฐ๋ณ์๋ POST ๋ฐฉ์์ผ๋ก ์ ์ก๋ฉ๋๋ค. ์ด ๊ธฐ๋ฅ์ ์ฃผ๋ก ์ธ์
์๋ณ์์ ๊ฐ์ ๋ณด์ ์ ๋ณด๋ฅผ URL์ ์ถ๊ฐํ๋ ๋ฐ ์ฌ์ฉ๋ฉ๋๋ค:
$link = new CLink('Secure Link', 'https://example.com');
$link->addSID();
echo $link->toString();์ด ์ฝ๋๋ ๋ค์๊ณผ ๊ฐ์ HTML์ ์ถ๋ ฅํฉ๋๋ค (์ค์ URL์ ๋์ ์ผ๋ก ์์ฑ๋ฉ๋๋ค):
<a href="javascript:void(0)" onclick="javascript: return Confirm('Are you sure?') && redirect('https://example.com?sid=YOUR_SESSION_ID', 'post', 'sid', true)">Secure Link</a>addConfirmation ๋ฉ์๋๋ฅผ ์ฌ์ฉํ์ฌ ๋งํฌ ํด๋ฆญ ์ ํ์ธ ๋ฉ์์ง๋ฅผ ํ์ํ ์ ์์ต๋๋ค:
$link = new CLink('Delete Item', 'https://example.com/delete');
$link->addConfirmation('Are you sure you want to delete this item?');
echo $link->toString();์ด ์ฝ๋๋ ๋ค์๊ณผ ๊ฐ์ HTML์ ์ถ๋ ฅํฉ๋๋ค:
<a href="https://example.com/delete" onclick="javascript: return Confirm('Are you sure you want to delete this item?');">Delete Item</a>๋ค์์ ๋ค์ํ ๊ธฐ๋ฅ์ ํ์ฉํ์ฌ a ํ๊ทธ๋ฅผ ์์ฑํ๋ ์ ์ฒด ์์ ์
๋๋ค:
use Jiny\Html\CLink;
$link = new CLink('Submit Form', 'https://example.com/submit');
$link->setTarget('_blank')
->addSID()
->addConfirmation('Are you sure you want to submit the form?');
echo $link->toString();์ด ์ฝ๋๋ ๋ค์๊ณผ ๊ฐ์ HTML์ ์ถ๋ ฅํฉ๋๋ค:
<a href="javascript:void(0)" onclick="javascript: return Confirm('Are you sure you want to submit the form?') && redirect('https://example.com/submit?sid=YOUR_SESSION_ID', 'post', 'sid', true)" target="_blank">Submit Form</a>์ด ๋ฌธ์์์๋ CLink ํด๋์ค๋ฅผ ์ฌ์ฉํ์ฌ a ํ๊ทธ๋ฅผ ์์ฑํ๊ณ , URL, ํ๊ฒ, ํ์ธ ๋ฉ์์ง ๋ฑ์ ์์ฑ์ ์ค์ ํ๋ ๋ฐฉ๋ฒ์ ๋ํด ์ค๋ช
ํ์ต๋๋ค. CLink ํด๋์ค๋ฅผ ํ์ฉํ๋ฉด ๋ค์ํ a ํ๊ทธ๋ฅผ ๊ฐ์ฒด ์งํฅ ๋ฐฉ์์ผ๋ก ์ฝ๊ฒ ์์ฑํ๊ณ ๊ด๋ฆฌํ ์ ์์ต๋๋ค.