<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Diễn đàn CakePHP Việt Nam</title>
	<atom:link href="http://cakephpvn.org/index.php/feed/" rel="self" type="application/rss+xml" />
	<link>http://cakephpvn.org</link>
	<description>cakephp, cakephp viet nam, cake, php, mysql, apache</description>
	<lastBuildDate>Sun, 25 Sep 2011 16:34:56 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.1.3</generator>
		<item>
		<title>CakePHP version 1.3.12</title>
		<link>http://cakephpvn.org/index.php/2011/09/25/cakephp-version-1-3-12/</link>
		<comments>http://cakephpvn.org/index.php/2011/09/25/cakephp-version-1-3-12/#comments</comments>
		<pubDate>Sun, 25 Sep 2011 16:33:44 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Phiên bản]]></category>
		<category><![CDATA[1.3.12]]></category>

		<guid isPermaLink="false">http://cakephpvn.org/?p=461</guid>
		<description><![CDATA[The CakePHP core team is proud to announce the immediate availability of CakePHP 1.2.11, 1.3.12 and 2.0.0-RC2. Both 1.2.11 and 1.3.12 are bugfix/maintenance releases. This triple release also contains the second iteration of the 2.0 version release candidates mostly featuring fixes, new test cases and a few new enhancements. There were no backwards incompatible changes [...]]]></description>
			<content:encoded><![CDATA[<p>The CakePHP core team is proud to announce the immediate availability of CakePHP 1.2.11, 1.3.12 and 2.0.0-RC2. Both 1.2.11 and 1.3.12 are bugfix/maintenance releases. This triple release also contains the second iteration of the 2.0 version release candidates mostly featuring fixes, new test cases and a few new enhancements. There were no backwards incompatible changes in any of three versions.<br />
<span id="more-461"></span><br />
For more information, please read <a href="http://bakery.cakephp.org/articles/lorenzo/2011/09/19/cakephp_triple_layered_edition_released" target="_blank">this topic</a></p>
<p><a href="http://bakery.cakephp.org/articles/lorenzo/2011/09/19/cakephp_triple_layered_edition_released"></a></p>
]]></content:encoded>
			<wfw:commentRss>http://cakephpvn.org/index.php/2011/09/25/cakephp-version-1-3-12/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Tạo chuỗi ngẫu nhiên với 1 dòng code</title>
		<link>http://cakephpvn.org/index.php/2011/09/06/tao-chuoi-ngau-nhien-voi-1-dong-code/</link>
		<comments>http://cakephpvn.org/index.php/2011/09/06/tao-chuoi-ngau-nhien-voi-1-dong-code/#comments</comments>
		<pubDate>Tue, 06 Sep 2011 06:59:41 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Chia sẻ]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[random string]]></category>

		<guid isPermaLink="false">http://cakephpvn.org/?p=458</guid>
		<description><![CDATA[Tạo chuỗi ngẫu nhiên với số ký tự tuỳ ý với 1 dòng code &#60;?php function createRandomString&#40;$len = 10&#41; &#123; $str = substr&#40; str_shuffle&#40; 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!@#$' &#41; , 0 , $len &#41;; return $str; &#125; ?&#62;]]></description>
			<content:encoded><![CDATA[<p>Tạo chuỗi ngẫu nhiên với số ký tự tuỳ ý với 1 dòng code</p>

<div class="wp_codebox"><table><tr id="p4582"><td class="code" id="p458code2"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
<span style="color: #000000; font-weight: bold;">function</span> createRandomString<span style="color: #009900;">&#40;</span><span style="color: #000088;">$len</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">10</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #000088;">$str</span> <span style="color: #339933;">=</span> <a href="http://www.php.net/substr"><span style="color: #990000;">substr</span></a><span style="color: #009900;">&#40;</span> <a href="http://www.php.net/str_shuffle"><span style="color: #990000;">str_shuffle</span></a><span style="color: #009900;">&#40;</span> <span style="color: #0000ff;">'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!@#$'</span> <span style="color: #009900;">&#41;</span> <span style="color: #339933;">,</span> <span style="color: #cc66cc;">0</span> <span style="color: #339933;">,</span> <span style="color: #000088;">$len</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #b1b100;">return</span> <span style="color: #000088;">$str</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></td></tr></table></div>

]]></content:encoded>
			<wfw:commentRss>http://cakephpvn.org/index.php/2011/09/06/tao-chuoi-ngau-nhien-voi-1-dong-code/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Kỹ thuật &#8220;bit field&#8221; trong phân quyền</title>
		<link>http://cakephpvn.org/index.php/2011/09/06/ky-thuat-bit-field-trong-phan-quyen/</link>
		<comments>http://cakephpvn.org/index.php/2011/09/06/ky-thuat-bit-field-trong-phan-quyen/#comments</comments>
		<pubDate>Tue, 06 Sep 2011 06:57:43 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Chia sẻ]]></category>
		<category><![CDATA[Kinh nghiệm]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[bitfield]]></category>

		<guid isPermaLink="false">http://cakephpvn.org/?p=456</guid>
		<description><![CDATA[Có thể nhiều bạn đã biết về kỹ thuật này, tuy nhiên, mình vẫn viết bài này, hi vọng các bạn chưa biết có thêm lựa chọn khi làm chức năng phân quyền trong các ứng dụng Giả sử module tin tức trong ứng dụng của mình có 4 chức năng: - Đọc tin - [...]]]></description>
			<content:encoded><![CDATA[<p>Có thể nhiều bạn đã biết về kỹ thuật này, tuy nhiên, mình vẫn viết bài này, hi vọng các bạn chưa biết có thêm lựa chọn khi làm chức năng phân quyền trong các ứng dụng<br />
<span id="more-456"></span></p>
<p>Giả sử module tin tức trong ứng dụng của mình có 4 chức năng:<br />
- Đọc tin<br />
- Thêm tin<br />
- Xóa tin<br />
- Sửa tin</p>
<p>Mình cần phân quyền cho 2 nhóm: admin và editor</p>
<p>Áp dụng kỹ thuật bit field, mình sẽ cho mỗi chức năng của module tin tức 1 con số đại diện, và lưu thành mảng</p>

<div class="wp_codebox"><table><tr id="p4565"><td class="code" id="p456code5"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$bitfields_news</span> <span style="color: #339933;">=</span> <a href="http://www.php.net/array"><span style="color: #990000;">array</span></a><span style="color: #009900;">&#40;</span>
    <span style="color: #0000ff;">'canview'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #cc66cc;">1</span><span style="color: #339933;">,</span>
    <span style="color: #0000ff;">'canadd'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #cc66cc;">2</span><span style="color: #339933;">,</span>
    <span style="color: #0000ff;">'canedit'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #cc66cc;">4</span><span style="color: #339933;">,</span>
    <span style="color: #0000ff;">'candelete'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #cc66cc;">8</span>
<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<p>Các bạn để ý các con số đại diện, tăng theo qui luật, số sau = số trước x 2 (bắt đầu từ 1)</p>
<p>Trong table groups, mình có cột news_permission, cột này sẽ cho biết admin hay editor có những quyền gì.</p>
<p>Giả sử admin có full quyền thì cột news_permission sẽ có giá trị:</p>
<p>1 + 2 + 4 + 8 = 15</p>
<p>Giả sử editor chỉ có quyền xem và sửa thì cột news_permission sẽ có giá trị:</p>
<p>1 + 4 = 5</p>
<p>Bảng groups sẽ như sau:</p>
<p>id_____name______news_permission<br />
1_____admin______15<br />
2_____editor______5</p>
<p>Bây giờ, ta sẽ xét quyền. Khi user nhấn delete một mẩu tin nào đó, ta sẽ check như sau:</p>

<div class="wp_codebox"><table><tr id="p4566"><td class="code" id="p456code6"><pre class="php" style="font-family:monospace;"><span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$users</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'Group'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'news_permission'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">&amp;</span> <span style="color: #cc66cc;">8</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #666666; font-style: italic;">// cho phep xoa</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p>Chú ý phép toán &#038;</p>
<p>Các bạn có thể dùng hàm decbin() để đổi sang nhị phân rồi đối chiếu</p>
<p>decbin(15) = 1111<br />
decbin(8) = 1000</p>
<p>Mã nguồn forum VBB sử dụng kỹ thuật này rất hiệu quả</p>
]]></content:encoded>
			<wfw:commentRss>http://cakephpvn.org/index.php/2011/09/06/ky-thuat-bit-field-trong-phan-quyen/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Làm việc với File và Folder</title>
		<link>http://cakephpvn.org/index.php/2011/07/03/lam-viec-voi-file-va-folder/</link>
		<comments>http://cakephpvn.org/index.php/2011/07/03/lam-viec-voi-file-va-folder/#comments</comments>
		<pubDate>Sun, 03 Jul 2011 05:52:15 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Manual]]></category>
		<category><![CDATA[file]]></category>
		<category><![CDATA[folder]]></category>

		<guid isPermaLink="false">http://cakephpvn.org/?p=450</guid>
		<description><![CDATA[Để làm việc với File và Folder trong cake, bạn có thể sử dụng 2 thư viện là File và Folder Xem API để biết về các method http://api13.cakephp.org/class/folder http://api13.cakephp.org/class/file Ví dụ: Liệt kê toàn bộ đường dẫn tới file và folder trong thư mục webroot Sử dụng hàm tree($p1, $p2, $p3) Trong đó: $p1: [...]]]></description>
			<content:encoded><![CDATA[<p>Để làm việc với File và Folder trong cake, bạn có thể sử dụng 2 thư viện là File và Folder</p>
<p><span id="more-450"></span>Xem API để biết về các method</p>
<p><a href="http://api13.cakephp.org/class/folder">http://api13.cakephp.org/class/folder</a></p>
<p><a href="http://api13.cakephp.org/class/file">http://api13.cakephp.org/class/file</a></p>
<p><strong>Ví dụ:</strong> Liệt kê toàn bộ đường dẫn tới file và folder trong thư mục webroot</p>
<p>Sử dụng hàm <strong>tree($p1, $p2, $p3)</strong></p>
<p><strong>Trong đó:</strong></p>
<p>$p1: thư mục cần liệt kê (dùng đường dẫn vật lý)<br />
$p2: mảng các files sẽ không liệt kê, mặc định không liệt kê files ẩn<br />
$p3: chỉ liệt kê file (file), chỉ liệt kê folder (dir) hoặc cả 2 (null). Mặc định là liệt kê cả file và folder</p>

<div class="wp_codebox"><table><tr id="p4509"><td class="code" id="p450code9"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$folder</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> Folder<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$arr</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$folder</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">tree</span><span style="color: #009900;">&#40;</span>WWW_ROOT<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
pr<span style="color: #009900;">&#40;</span><span style="color: #000088;">$arr</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<p>Kết quả:</p>

<div class="wp_codebox"><table><tr id="p45010"><td class="code" id="p450code10"><pre class="php" style="font-family:monospace;"><a href="http://www.php.net/array"><span style="color: #990000;">Array</span></a>
<span style="color: #009900;">&#40;</span>
<span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=&gt;</span> <a href="http://www.php.net/array"><span style="color: #990000;">Array</span></a>
<span style="color: #009900;">&#40;</span>
<span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=&gt;</span> D<span style="color: #339933;">:</span>\wamp\www\cake_test\webroot
<span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=&gt;</span> D<span style="color: #339933;">:</span>\wamp\www\cake_test\webroot\js
<span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">2</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=&gt;</span> D<span style="color: #339933;">:</span>\wamp\www\cake_test\webroot\js\ext
<span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">3</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=&gt;</span> D<span style="color: #339933;">:</span>\wamp\www\cake_test\webroot\img
<span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">4</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=&gt;</span> D<span style="color: #339933;">:</span>\wamp\www\cake_test\webroot\css
<span style="color: #009900;">&#41;</span>
&nbsp;
<span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=&gt;</span> <a href="http://www.php.net/array"><span style="color: #990000;">Array</span></a>
<span style="color: #009900;">&#40;</span>
<span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=&gt;</span> D<span style="color: #339933;">:</span>\wamp\www\cake_test\webroot\css<span style="color: #339933;">.</span>php
<span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=&gt;</span> D<span style="color: #339933;">:</span>\wamp\www\cake_test\webroot\favicon<span style="color: #339933;">.</span>ico
<span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">2</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=&gt;</span> D<span style="color: #339933;">:</span>\wamp\www\cake_test\webroot\index<span style="color: #339933;">.</span>php
<span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">3</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=&gt;</span> D<span style="color: #339933;">:</span>\wamp\www\cake_test\webroot\test<span style="color: #339933;">.</span>php
<span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">4</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=&gt;</span> D<span style="color: #339933;">:</span>\wamp\www\cake_test\webroot\Thumbs<span style="color: #339933;">.</span>db
<span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">5</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=&gt;</span> D<span style="color: #339933;">:</span>\wamp\www\cake_test\webroot\js\ext\examples<span style="color: #339933;">.</span>js
<span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">6</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=&gt;</span> D<span style="color: #339933;">:</span>\wamp\www\cake_test\webroot\js\ext\paging<span style="color: #339933;">.</span>js
<span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">7</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=&gt;</span> D<span style="color: #339933;">:</span>\wamp\www\cake_test\webroot\img\cake<span style="color: #339933;">.</span>icon<span style="color: #339933;">.</span>png
<span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">8</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=&gt;</span> D<span style="color: #339933;">:</span>\wamp\www\cake_test\webroot\img\cake<span style="color: #339933;">.</span>power<span style="color: #339933;">.</span>gif
<span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">9</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=&gt;</span> D<span style="color: #339933;">:</span>\wamp\www\cake_test\webroot\css\cake<span style="color: #339933;">.</span>generic<span style="color: #339933;">.</span>css
<span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">10</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=&gt;</span> D<span style="color: #339933;">:</span>\wamp\www\cake_test\webroot\css\grid<span style="color: #339933;">-</span>examples<span style="color: #339933;">.</span>css
<span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#41;</span></pre></td></tr></table></div>

<p>Xem code:</p>
<p><a href="http://api13.cakephp.org/view_source/folder/#line-423">http://api13.cakephp.org/view_source/folder/#line-423</a></p>
<p>Tương tự cho các hàm khác và thư viện File. API của cake cung cấp rất đầy đủ!</p>
]]></content:encoded>
			<wfw:commentRss>http://cakephpvn.org/index.php/2011/07/03/lam-viec-voi-file-va-folder/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>CakePHP 1.3.8</title>
		<link>http://cakephpvn.org/index.php/2011/03/28/cakephp-1-3-8/</link>
		<comments>http://cakephpvn.org/index.php/2011/03/28/cakephp-1-3-8/#comments</comments>
		<pubDate>Sun, 27 Mar 2011 17:26:57 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Phiên bản]]></category>
		<category><![CDATA[1.3.8]]></category>

		<guid isPermaLink="false">http://cakephpvn.org/?p=445</guid>
		<description><![CDATA[The CakePHP core team is proud to announce the immediate availability of CakePHP 1.3.8 and 1.2.10. These releases are bugfix/maintenance releases for the 1.2 and 1.3 branches. Change log: http://cakephp.org/changelogs/1.3.8]]></description>
			<content:encoded><![CDATA[<p>The CakePHP core team is proud to announce the immediate availability of CakePHP 1.3.8 and 1.2.10. These releases are bugfix/maintenance releases for the 1.2 and 1.3 branches.<br />
<span id="more-445"></span><br />
Change log:</p>
<p>http://cakephp.org/changelogs/1.3.8</p>
]]></content:encoded>
			<wfw:commentRss>http://cakephpvn.org/index.php/2011/03/28/cakephp-1-3-8/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>CakePHP 1.3.7 Released</title>
		<link>http://cakephpvn.org/index.php/2011/02/16/cakephp-1-3-7-released/</link>
		<comments>http://cakephpvn.org/index.php/2011/02/16/cakephp-1-3-7-released/#comments</comments>
		<pubDate>Wed, 16 Feb 2011 16:50:10 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Phiên bản]]></category>
		<category><![CDATA[1.3.7]]></category>

		<guid isPermaLink="false">http://cakephpvn.org/?p=441</guid>
		<description><![CDATA[The CakePHP core team is proud to announce the immediate availability of CakePHP release 1.3.7. Since the release of CakePHP 1.3.6 a month and half ago, there have been over 55 commits[1] and 40 tickets resolved. There have been a few changes that may affect your application: Usage of serialize() was removed from SecurityComponent. View::element() [...]]]></description>
			<content:encoded><![CDATA[<p>The CakePHP core team is proud to announce the immediate availability of CakePHP release 1.3.7. Since the release of CakePHP 1.3.6 a month and half ago, there have been over 55 commits[1] and 40 tickets resolved.<br />
<span id="more-441"></span></p>
<p>There have been a few changes that may affect your application:</p>
<p>Usage of serialize() was removed from SecurityComponent.<br />
View::element() now correctly uses &#8216;.ctp&#8217; as a fallback extension.<br />
View variables are now passed to CacheHelper, making view caches more powerful.<br />
EmailComponent now registers and un-registers its view class, this fixes issues where helpers needing a view would trigger errors.<br />
Memcache engine now correctly stores entries with expiry dates greater than 30 days.<br />
Empty session ids no longer cause errors with database session storage.<br />
TextHelper::autoLinkEmails works with emails containing &#8216;.<br />
Console test suite now exits with a non zero code on test failure.<br />
Download the release[2] today, and catch up on the updates by perusing the changelog[1].</p>
<p>Development on 2.0 is continuing well, and thanks to everyone who has taken the time to give it a spin and report any issues found with it. At this time we will start removing the changelog wiki pages on lighthouse. Instead all changelogs can be found on cakephp.org itself[1]. This will keep the wiki list shorter, and solves issues with long changelogs not fitting onto a single wiki page in lighthouse.</p>
<p>The CakePHP team is considering a change in how documentation is generated for future versions. While the current book.cakephp.org application has served us extremely well over the past 3 years, we are always looking to improve the documentation for CakePHP. We frequently get requests for documentation in other formats, such as CHM, PDF and e-books. Its also become evident over time that converting the book content into these formats is no small task. In order to address these needs, we&#8217;re considering moving the documentation for 2.0 into text files, and using a tool like sphinx[4] to generate the documentation. Sphinx is used for documentation by a number of large open source projects such as Python, Django and Bazaar. We feel that this approach will allow us to provide documentation in a number of requested formats, as well as maintain the existing work on translations and involve the community through contributions. However, documentation is a community effort, and we&#8217;d like some feedback on the direction we take with the documentation. Leave a comment with your thoughts on the proposed documentation changes.</p>
<p>These are exciting times for CakePHP documentation, the new CakePHPTV[5] site is gaining momentum and some great tutorials have been already published. We&#8217;d like to remind you that the video tutorials contest is in place until February 14, when we will be counting community votes for your tutorials and start giving away awesome prizes including a brand new iPad. Don&#8217;t forget to get your screen cast filmed and enter the contest at tv.cakephp.org to start participating!</p>
<p>A huge thanks to all involved in terms of both contributions through commits and diffs, as well as those that took the time and effort to submit tickets, update documentation and otherwise contribute to the framework. Without you there would be no CakePHP.</p>
<p>View the changelog[1]<br />
Download a packaged release [2]<br />
Links</p>
<p>[1] http://cakephp.org/changelogs/1.3.7<br />
[2] http://github.com/cakephp/cakephp/downloads<br />
[3] http://cakephp.lighthouseapp.com/projects/42648<br />
[4] http://sphinx.pocoo.org/<br />
[5] http://tv.cakephp.org/launch-competition</p>
]]></content:encoded>
			<wfw:commentRss>http://cakephpvn.org/index.php/2011/02/16/cakephp-1-3-7-released/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Ajax trong CakePHP</title>
		<link>http://cakephpvn.org/index.php/2010/11/23/ajax-trong-cakephp/</link>
		<comments>http://cakephpvn.org/index.php/2010/11/23/ajax-trong-cakephp/#comments</comments>
		<pubDate>Mon, 22 Nov 2010 17:36:31 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Chia sẻ]]></category>
		<category><![CDATA[Tutorial]]></category>
		<category><![CDATA[ajax]]></category>
		<category><![CDATA[jquery]]></category>

		<guid isPermaLink="false">http://cakephpvn.org/?p=430</guid>
		<description><![CDATA[Chắc cái này cũng có nhiều bạn quan tâm, bài này nói về vấn đề ajax trong cakephp, sử dụng thư viện jquery 1. Tải jquery https://ajax.googleapis.com/ajax/libs/jquery/1.4.4/jquery.min.js Copy file jquery.min.js vào app/webroot/js 2. Mở file layout, chèn code sau: echo $javascript-&#62;link&#40;'jquery.min.js'&#41;; 3. Controller (ở đây mình dùng file product_category_controller.php từ các ví dụ trước), tạo [...]]]></description>
			<content:encoded><![CDATA[<p>Chắc cái này cũng có nhiều bạn quan tâm, bài này nói về vấn đề ajax trong cakephp, sử dụng thư viện jquery<br />
<span id="more-430"></span><br />
<strong>1. Tải jquery</strong></p>
<p><a href="https://ajax.googleapis.com/ajax/libs/jquery/1.4.4/jquery.min.js">https://ajax.googleapis.com/ajax/libs/jquery/1.4.4/jquery.min.js</a></p>
<p>Copy file <strong>jquery.min.js</strong> vào <strong>app/webroot/js</strong></p>
<p><strong>2. Mở file layout</strong>, chèn code sau:</p>

<div class="wp_codebox"><table><tr id="p43021"><td class="code" id="p430code21"><pre class="php" style="font-family:monospace;"><span style="color: #b1b100;">echo</span> <span style="color: #000088;">$javascript</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">link</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'jquery.min.js'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<p><strong>3. Controller</strong> (ở đây mình dùng file product_category_controller.php từ các ví dụ trước), tạo 2 hàm</p>

<div class="wp_codebox"><table><tr id="p43022"><td class="code" id="p430code22"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">function</span> add<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
&nbsp;
    <span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">function</span> ajax_add<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">layout</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'ajax'</span><span style="color: #339933;">;</span>
        <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">autoRender</span> <span style="color: #339933;">=</span> <span style="color: #009900; font-weight: bold;">false</span><span style="color: #339933;">;</span>
        <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span><a href="http://www.php.net/empty"><span style="color: #990000;">empty</span></a><span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">data</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
            <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">ProductCategory</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">create</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>            
            <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">ProductCategory</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">save</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">data</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
                <span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">'The product category has been saved'</span><span style="color: #339933;">;</span>                
            <span style="color: #009900;">&#125;</span> <span style="color: #b1b100;">else</span> <span style="color: #009900;">&#123;</span>
                <span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">'The product category could not be saved. Please, try again.'</span><span style="color: #339933;">;</span>
            <span style="color: #009900;">&#125;</span>
        <span style="color: #009900;">&#125;</span>        
    <span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p>- Bạn nào chưa có file <strong>ajax.ctp</strong> trong <strong>app/views/layouts</strong> thì tự tạo ra nhé, nội dung trong file chỉ cần để:</p>

<div class="wp_codebox"><table><tr id="p43023"><td class="code" id="p430code23"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">echo</span> <span style="color: #000088;">$content_for_layout</span><span style="color: #339933;">;</span><span style="color: #000000; font-weight: bold;">?&gt;</span></pre></td></tr></table></div>

<p><strong>4. View</strong></p>

<div class="wp_codebox"><table><tr id="p43024"><td class="code" id="p430code24"><pre class="php" style="font-family:monospace;"><span style="color: #339933;">&lt;</span>div <span style="color: #000000; font-weight: bold;">class</span><span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;productCategories form&quot;</span><span style="color: #339933;">&gt;</span>
<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">echo</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">Form</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">create</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'ProductCategory'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><span style="color: #000000; font-weight: bold;">?&gt;</span>
    <span style="color: #339933;">&lt;</span>fieldset<span style="color: #339933;">&gt;</span>
         <span style="color: #339933;">&lt;</span>legend<span style="color: #339933;">&gt;</span><span style="color: #000000; font-weight: bold;">&lt;?</span>php __<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Add Product Category'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span><span style="color: #339933;">&lt;/</span>legend<span style="color: #339933;">&gt;</span>
    <span style="color: #000000; font-weight: bold;">&lt;?php</span>
        <span style="color: #b1b100;">echo</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">Form</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">input</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'name'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #b1b100;">echo</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">Form</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">input</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'parent_id'</span><span style="color: #339933;">,</span><a href="http://www.php.net/array"><span style="color: #990000;">array</span></a><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'type'</span><span style="color: #339933;">=&gt;</span><span style="color: #0000ff;">'select'</span><span style="color: #339933;">,</span><span style="color: #0000ff;">'options'</span><span style="color: #339933;">=&gt;</span><span style="color: #000088;">$list_cat</span><span style="color: #339933;">,</span><span style="color: #0000ff;">'empty'</span><span style="color: #339933;">=&gt;</span><span style="color: #0000ff;">'--Choose parent--'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>        
        <span style="color: #b1b100;">echo</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">Form</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">input</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'published'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>        
    <span style="color: #000000; font-weight: bold;">?&gt;</span>
    <span style="color: #339933;">&lt;/</span>fieldset<span style="color: #339933;">&gt;</span>
<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">echo</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">Form</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">button</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Submit'</span><span style="color: #339933;">,</span> <a href="http://www.php.net/array"><span style="color: #990000;">array</span></a><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'onclick'</span><span style="color: #339933;">=&gt;</span><span style="color: #0000ff;">'doSubmit(); return false;'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>
<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">echo</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">Form</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">end</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>
<span style="color: #339933;">&lt;/</span>div<span style="color: #339933;">&gt;</span>
<span style="color: #339933;">&lt;</span>div <span style="color: #000000; font-weight: bold;">class</span><span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;actions&quot;</span><span style="color: #339933;">&gt;</span>
    <span style="color: #339933;">&lt;</span>h3<span style="color: #339933;">&gt;</span><span style="color: #000000; font-weight: bold;">&lt;?</span>php __<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Actions'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span><span style="color: #339933;">&lt;/</span>h3<span style="color: #339933;">&gt;</span>
    <span style="color: #339933;">&lt;</span>ul<span style="color: #339933;">&gt;</span>
&nbsp;
        <span style="color: #339933;">&lt;</span>li<span style="color: #339933;">&gt;</span><span style="color: #000000; font-weight: bold;">&lt;?</span>php <span style="color: #b1b100;">echo</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">Html</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">link</span><span style="color: #009900;">&#40;</span>__<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'List Product Categories'</span><span style="color: #339933;">,</span> <span style="color: #009900; font-weight: bold;">true</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span> <a href="http://www.php.net/array"><span style="color: #990000;">array</span></a><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'action'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'index'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><span style="color: #000000; font-weight: bold;">?&gt;</span><span style="color: #339933;">&lt;/</span>li<span style="color: #339933;">&gt;</span>
    <span style="color: #339933;">&lt;/</span>ul<span style="color: #339933;">&gt;</span>
<span style="color: #339933;">&lt;/</span>div<span style="color: #339933;">&gt;</span>
<span style="color: #339933;">&lt;</span>div id<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;starting&quot;</span><span style="color: #339933;">&gt;</span>Starting<span style="color: #339933;">...&lt;/</span>div<span style="color: #339933;">&gt;</span>
<span style="color: #339933;">&lt;</span>div id<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;sending&quot;</span><span style="color: #339933;">&gt;</span>Sending<span style="color: #339933;">...&lt;/</span>div<span style="color: #339933;">&gt;</span>
<span style="color: #339933;">&lt;</span>div id<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;success&quot;</span><span style="color: #339933;">&gt;</span>Successful<span style="color: #339933;">...&lt;/</span>div<span style="color: #339933;">&gt;</span>
<span style="color: #339933;">&lt;</span>div id<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;complete&quot;</span><span style="color: #339933;">&gt;</span>Complete<span style="color: #339933;">...&lt;/</span>div<span style="color: #339933;">&gt;</span>
Got this in response<span style="color: #339933;">:</span> <span style="color: #339933;">&lt;</span>div id<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;results&quot;</span><span style="color: #339933;">&gt;&lt;/</span>div<span style="color: #339933;">&gt;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">&lt;script language</span><span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;javascript&quot;</span><span style="color: #339933;">&gt;</span>
$<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;#starting&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">.</span>hide<span style="color: #009900;">&#40;</span>  <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
$<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;#sending&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">.</span>hide<span style="color: #009900;">&#40;</span>  <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
$<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;#success&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">.</span>hide<span style="color: #009900;">&#40;</span>  <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
$<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;#complete&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">.</span>hide<span style="color: #009900;">&#40;</span>  <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">function</span> doSubmit<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
    $<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;#starting&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">.</span>bind<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;ajaxStart&quot;</span><span style="color: #339933;">,</span>
        <span style="color: #000000; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>  <span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
            $<span style="color: #009900;">&#40;</span>this<span style="color: #009900;">&#41;</span><span style="color: #339933;">.</span>show<span style="color: #009900;">&#40;</span>  <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    $<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;#sending&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">.</span>bind<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;ajaxSend&quot;</span><span style="color: #339933;">,</span> 
        <span style="color: #000000; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>  <span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
         $<span style="color: #009900;">&#40;</span>this<span style="color: #009900;">&#41;</span><span style="color: #339933;">.</span>show<span style="color: #009900;">&#40;</span>  <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    $<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;#success&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">.</span>bind<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;ajaxSuccess&quot;</span><span style="color: #339933;">,</span>  
        <span style="color: #000000; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>  <span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
            $<span style="color: #009900;">&#40;</span>this<span style="color: #009900;">&#41;</span><span style="color: #339933;">.</span>show<span style="color: #009900;">&#40;</span>  <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    $<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;#complete&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">.</span>bind<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;ajaxComplete&quot;</span><span style="color: #339933;">,</span> 
        <span style="color: #000000; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>  <span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
            $<span style="color: #009900;">&#40;</span>this<span style="color: #009900;">&#41;</span><span style="color: #339933;">.</span>show<span style="color: #009900;">&#40;</span>  <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">var</span> data <span style="color: #339933;">=</span> $<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;#ProductCategoryAddForm&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">.</span><a href="http://www.php.net/serialize"><span style="color: #990000;">serialize</span></a><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    $<span style="color: #339933;">.</span>ajax<span style="color: #009900;">&#40;</span>
        <span style="color: #009900;">&#123;</span>
            type<span style="color: #339933;">:</span> <span style="color: #0000ff;">&quot;post&quot;</span><span style="color: #339933;">,</span>
            url<span style="color: #339933;">:</span> <span style="color: #0000ff;">&quot;ajax_add&quot;</span><span style="color: #339933;">,</span>
            data<span style="color: #339933;">:</span> data<span style="color: #339933;">,</span>
            success<span style="color: #339933;">:</span> callback
        <span style="color: #009900;">&#125;</span>
    <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">function</span> callback<span style="color: #009900;">&#40;</span>data<span style="color: #339933;">,</span> status<span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
    $<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;#results&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">.</span>text<span style="color: #009900;">&#40;</span>data<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
<span style="color: #000000; font-weight: bold;">&lt;/script&gt;</span></pre></td></tr></table></div>

<p>Nếu thành công, sau khi nhấn nút submit bạn sẽ nhận được thông tin như sau:</p>
<p><em><br />
Starting&#8230;<br />
Sending&#8230;<br />
Successful&#8230;<br />
Complete&#8230;<br />
Got this in response:<br />
The product category has been saved</em></p>
<p><strong>5. Giải thích</strong></p>
<p>- Bước 1 &#038; 2: không có gì phải bàn cãi</p>
<p>- Bước 3: mình viết riêng 2 hàm add, trong đó hàm đầu tiên không có nội dung gì cả! Lí do là mình load cái form add lên thì ko dùng ajax nhưng khi submit form thì lại dùng ajax</p>
<p>- Bước 4:</p>
<p>+ Mình tạo ra 1 nút submit riêng, khi click sẽ gọi hàm doSubmit() mà mình viết bên dưới, sau đó return false để nó khỏi về trang index, mục đích return false là để nó dừng việc redirect để mình thấy câu thông báo trả về trên các div đã định trước. Khi làm thực tế các bạn bỏ return false ra.</p>

<div class="wp_codebox"><table><tr id="p43025"><td class="code" id="p430code25"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">echo</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">Form</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">button</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Submit'</span><span style="color: #339933;">,</span> <a href="http://www.php.net/array"><span style="color: #990000;">array</span></a><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'onclick'</span><span style="color: #339933;">=&gt;</span><span style="color: #0000ff;">'doSubmit(); return false;'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span></pre></td></tr></table></div>

<p>+ Tiếp đó, mình tạo ra vài thẻ div để show thông tin cho biết việc gọi ajax trả về cho ta những gì. Khi làm thực tế bạn chỉ cần 1 thẻ div sau cùng, báo cho người dùng là dữ liệu đã xử lý thành công.</p>

<div class="wp_codebox"><table><tr id="p43026"><td class="code" id="p430code26"><pre class="html" style="font-family:monospace;">&lt;div id=&quot;starting&quot;&gt;Starting...&lt;/div&gt;
&lt;div id=&quot;sending&quot;&gt;Sending...&lt;/div&gt;
&lt;div id=&quot;success&quot;&gt;Successful...&lt;/div&gt;
&lt;div id=&quot;complete&quot;&gt;Complete...&lt;/div&gt;
Got this in response: &lt;div id=&quot;results&quot;&gt;&lt;/div&gt;</pre></td></tr></table></div>

<p>+ Cuối cùng là phần js</p>
<p>- Đầu tiên, mình ẩn các thẻ div ở trên đi:</p>

<div class="wp_codebox"><table><tr id="p43027"><td class="code" id="p430code27"><pre class="javascript" style="font-family:monospace;">$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;#starting&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">hide</span><span style="color: #009900;">&#40;</span>  <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;#sending&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">hide</span><span style="color: #009900;">&#40;</span>  <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;#success&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">hide</span><span style="color: #009900;">&#40;</span>  <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;#complete&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">hide</span><span style="color: #009900;">&#40;</span>  <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<p>- Sau đó, trong hàm <strong>doSubmit()</strong>, tương ứng với từng trạng thái của ajax: Start, Send, Success, Complete mình sẽ show cái div đó ra để nhận biết</p>

<div class="wp_codebox"><table><tr id="p43028"><td class="code" id="p430code28"><pre class="javascript" style="font-family:monospace;">$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;#starting&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">bind</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;ajaxStart&quot;</span><span style="color: #339933;">,</span>
        <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>  <span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
            $<span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">show</span><span style="color: #009900;">&#40;</span>  <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;#sending&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">bind</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;ajaxSend&quot;</span><span style="color: #339933;">,</span> 
        <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>  <span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
         $<span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">show</span><span style="color: #009900;">&#40;</span>  <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;#success&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">bind</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;ajaxSuccess&quot;</span><span style="color: #339933;">,</span>  
        <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>  <span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
            $<span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">show</span><span style="color: #009900;">&#40;</span>  <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;#complete&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">bind</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;ajaxComplete&quot;</span><span style="color: #339933;">,</span> 
        <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>  <span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
            $<span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">show</span><span style="color: #009900;">&#40;</span>  <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<p>- Và quan trọng hơn cả là code này</p>

<div class="wp_codebox"><table><tr id="p43029"><td class="code" id="p430code29"><pre class="javascript" style="font-family:monospace;"><span style="color: #003366; font-weight: bold;">var</span> data <span style="color: #339933;">=</span> $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;#ProductCategoryAddForm&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">serialize</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    $.<span style="color: #660066;">ajax</span><span style="color: #009900;">&#40;</span>
        <span style="color: #009900;">&#123;</span>
            type<span style="color: #339933;">:</span> <span style="color: #3366CC;">&quot;post&quot;</span><span style="color: #339933;">,</span>
            url<span style="color: #339933;">:</span> <span style="color: #3366CC;">&quot;ajax_add&quot;</span><span style="color: #339933;">,</span>
            data<span style="color: #339933;">:</span> data<span style="color: #339933;">,</span>
            success<span style="color: #339933;">:</span> callback
        <span style="color: #009900;">&#125;</span>
    <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<p>Bạn phải tiến hành <strong>serialize()</strong> cái form để nó có thể lấy được data trả về.<br />
ProductCategoryAddForm là id của form do cake tạo ra, bạn có thể view source để lấy hoặc tự set id cho form</p>
<p><strong>url: &#8220;ajax_add&#8221;</strong>: chính là action ajax_add đã định nghĩa trong controller</p>
<p>- Nếu mọi thứ thành công, sau cùng nó sẽ gọi hàm callback</p>

<div class="wp_codebox"><table><tr id="p43030"><td class="code" id="p430code30"><pre class="javascript" style="font-family:monospace;"><span style="color: #003366; font-weight: bold;">function</span> callback<span style="color: #009900;">&#40;</span>data<span style="color: #339933;">,</span> <span style="color: #000066;">status</span><span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
    $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;#results&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">text</span><span style="color: #009900;">&#40;</span>data<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p>Hàm này đơn giản là show data lấy được từ form lên cái div có di results. Thực tế, sau khi post form xong thì bạn có thể thực thi tiếp 1 tác vụ nào đó, khi đó bạn viết function tương ứng rồi quăng vô <strong>success:</strong> để nó làm</p>
<p>Hi vọng là các bạn ứng dụng thành công!</p>
]]></content:encoded>
			<wfw:commentRss>http://cakephpvn.org/index.php/2010/11/23/ajax-trong-cakephp/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Tạo và load file config trong CakePHP</title>
		<link>http://cakephpvn.org/index.php/2010/11/23/tao-va-load-file-config-trong-cakephp/</link>
		<comments>http://cakephpvn.org/index.php/2010/11/23/tao-va-load-file-config-trong-cakephp/#comments</comments>
		<pubDate>Mon, 22 Nov 2010 17:29:58 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Chia sẻ]]></category>
		<category><![CDATA[Kinh nghiệm]]></category>
		<category><![CDATA[Configure]]></category>

		<guid isPermaLink="false">http://cakephpvn.org/?p=428</guid>
		<description><![CDATA[Bài hôm nay mình sẽ hướng dẫn các bạn tự tạo file cấu hình cho riêng mình và load file này lên, sau đó dùng Configure::read($key) để đọc config lên như thông thường. Để thiết lập những cấu hình cho web viết trên nền CakePHP, bạn có thể mở file config/core.php và thêm vào theo [...]]]></description>
			<content:encoded><![CDATA[<p>Bài hôm nay mình sẽ hướng dẫn các bạn tự tạo file cấu hình cho riêng mình và load file này lên, sau đó dùng <strong>Configure::read($key)</strong> để đọc config lên như thông thường.<br />
<span id="more-428"></span><br />
Để thiết lập những cấu hình cho web viết trên nền CakePHP, bạn có thể mở file <strong>config/core.php</strong> và thêm vào theo dạng:</p>

<div class="wp_codebox"><table><tr id="p42835"><td class="code" id="p428code35"><pre class="php" style="font-family:monospace;">Configure<span style="color: #339933;">::</span><span style="color: #004000;">write</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$key</span><span style="color: #339933;">,</span> <span style="color: #000088;">$value</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<p>Đã có bài viết về việc sử dụng lớp Configure, các bạn đọc để hiểu rõ hơn.</p>
<p>Bắt đầu nào&#8230;</p>
<p>Đầu tiên, bạn tạo file có tên bất kỳ lưu vào thư mục <strong>config</strong>. Ở đây mình tạo file <strong>my_configs.php</strong>, nội dung như bên dưới, đây chỉ là ví dụ, bạn có thể có nhiều thông số khác:</p>

<div class="wp_codebox"><table><tr id="p42836"><td class="code" id="p428code36"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$config</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'site'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'folder'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">''</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$config</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'frontend'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'url'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'http://'</span><span style="color: #339933;">.</span><span style="color: #000088;">$_SERVER</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'HTTP_HOST'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">.</span><span style="color: #000088;">$config</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'site'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'folder'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">.</span><span style="color: #0000ff;">'/'</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000088;">$admin</span> <span style="color: #339933;">=</span> Configure<span style="color: #339933;">::</span><span style="color: #004000;">read</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Routing.prefixes'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$config</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'backend'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'folder'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$admin</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$config</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'backend'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'url'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$config</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'frontend'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'url'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">.</span><span style="color: #000088;">$admin</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">.</span><span style="color: #0000ff;">'/'</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$config</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'backend'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'rows_per_page'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">10</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<p>Bạn lưu ý: biến lưu trữ phải có tên là <strong>$config</strong> nhé!</p>
<p>Sau đó, mở file <strong>app_controller.php</strong>, thêm code sau vào hàm <strong>beforeFilter()</strong></p>

<div class="wp_codebox"><table><tr id="p42837"><td class="code" id="p428code37"><pre class="php" style="font-family:monospace;">Configure<span style="color: #339933;">::</span><span style="color: #004000;">load</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'my_configs'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<p>Để đọc config, ví dụ, mình muốn lấy config có key là: rows_per_page thì code sẽ là:</p>

<div class="wp_codebox"><table><tr id="p42838"><td class="code" id="p428code38"><pre class="php" style="font-family:monospace;">Configure<span style="color: #339933;">::</span><span style="color: #004000;">read</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'backend.rows_per_page'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

]]></content:encoded>
			<wfw:commentRss>http://cakephpvn.org/index.php/2010/11/23/tao-va-load-file-config-trong-cakephp/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Làm site đa ngôn ngữ với CakePHP (Phần 1)</title>
		<link>http://cakephpvn.org/index.php/2010/11/21/lam-site-da-ngon-ngu-voi-cakephp-phan-1/</link>
		<comments>http://cakephpvn.org/index.php/2010/11/21/lam-site-da-ngon-ngu-voi-cakephp-phan-1/#comments</comments>
		<pubDate>Sat, 20 Nov 2010 17:41:20 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Tutorial]]></category>
		<category><![CDATA[translate]]></category>
		<category><![CDATA[đa ngôn ngữ]]></category>

		<guid isPermaLink="false">http://cakephpvn.org/?p=424</guid>
		<description><![CDATA[Bài viết này có 2 phần: đa ngôn ngữ cho nội dung và cho giao diện. Phần 1 sẽ hướng dẫn các bạn thiết lập phần đa ngôn ngữ cho nội dung. Trong diễn đàn đã có bài viết hướng dẫn cách làm site đa ngôn ngữ cho cả nội dung và giao diện của [...]]]></description>
			<content:encoded><![CDATA[<p>Bài viết này có 2 phần: đa ngôn ngữ cho nội dung và cho giao diện. Phần 1 sẽ hướng dẫn các bạn thiết lập phần đa ngôn ngữ cho nội dung.</p>
<p>Trong diễn đàn đã có bài viết hướng dẫn cách làm site đa ngôn ngữ cho cả nội dung và giao diện của bạn tien12d, các bạn tham khảo: http://cakephpvn.org/forum/showthread.php?tid=60</p>
<p>Mình sẽ viết lại chủ đề này theo cách của mình, hi vọng với 2 bài viết cho cùng 1 chủ đề, các bạn sẽ làm được điều mình muốn 1 cách tốt nhất!<br />
<span id="more-424"></span></p>
<p><strong>1. Xây dựng db</strong></p>
<p>- Các bạn chạy câu sql sau để tạo table lưu trữ dữ liệu đa ngôn ngữ. Tạm thời chúng ta sẽ nhét toàn bộ nội dung đa ngôn ngữ của tất cả các table vào table này, mình sẽ chỉ cách tách nhỏ dữ liệu ra sau.</p>

<div class="wp_codebox"><table><tr id="p42449"><td class="code" id="p424code49"><pre class="mysql" style="font-family:monospace;"><span style="color: #CC0099;">--</span>
<span style="color: #808080; font-style: italic;">-- Table structure for table `i18n`</span>
<span style="color: #CC0099;">--</span>
&nbsp;
<a href="http://search.mysql.com/search?site=refman-%35%31&amp;q=CREATE"><span style="color: #990099; font-weight: bold;">CREATE</span></a> <a href="http://search.mysql.com/search?site=refman-%35%31&amp;q=TABLE"><span style="color: #990099; font-weight: bold;">TABLE</span></a> <a href="http://search.mysql.com/search?site=refman-%35%31&amp;q=IF%20NOT%20EXISTS"><span style="color: #990099; font-weight: bold;">IF <a href="http://dev.mysql.com/doc/refman/%35%2E%31/en/non-typed-operators.html"><span style="color: #CC0099; font-weight: bold;">NOT</span></a> EXISTS</span></a> <span style="color: #008000;">`i18n`</span> <span style="color: #FF00FF;">&#40;</span>
  <span style="color: #008000;">`id`</span> <a href="http://search.mysql.com/search?site=refman-%35%31&amp;q=INT"><span style="color: #999900; font-weight: bold;">int</span></a><span style="color: #FF00FF;">&#40;</span><span style="color: #008080;">10</span><span style="color: #FF00FF;">&#41;</span> <a href="http://dev.mysql.com/doc/refman/%35%2E%31/en/non-typed-operators.html"><span style="color: #CC0099; font-weight: bold;">NOT</span></a> <a href="http://search.mysql.com/search?site=refman-%35%31&amp;q=NULL"><span style="color: #9900FF; font-weight: bold;">NULL</span></a> <a href="http://search.mysql.com/search?site=refman-%35%31&amp;q=AUTO_INCREMENT"><span style="color: #FF9900; font-weight: bold;">AUTO_INCREMENT</span></a><span style="color: #000033;">,</span>
  <span style="color: #008000;">`locale`</span> <a href="http://search.mysql.com/search?site=refman-%35%31&amp;q=VARCHAR"><span style="color: #999900; font-weight: bold;">varchar</span></a><span style="color: #FF00FF;">&#40;</span><span style="color: #008080;">6</span><span style="color: #FF00FF;">&#41;</span> CHARACTER <a href="http://search.mysql.com/search?site=refman-%35%31&amp;q=SET"><span style="color: #990099; font-weight: bold;">SET</span></a> utf8 <a href="http://dev.mysql.com/doc/refman/%35%2E%31/en/non-typed-operators.html"><span style="color: #CC0099; font-weight: bold;">NOT</span></a> <a href="http://search.mysql.com/search?site=refman-%35%31&amp;q=NULL"><span style="color: #9900FF; font-weight: bold;">NULL</span></a><span style="color: #000033;">,</span>
  <span style="color: #008000;">`model`</span> <a href="http://search.mysql.com/search?site=refman-%35%31&amp;q=VARCHAR"><span style="color: #999900; font-weight: bold;">varchar</span></a><span style="color: #FF00FF;">&#40;</span><span style="color: #008080;">255</span><span style="color: #FF00FF;">&#41;</span> CHARACTER <a href="http://search.mysql.com/search?site=refman-%35%31&amp;q=SET"><span style="color: #990099; font-weight: bold;">SET</span></a> utf8 <a href="http://dev.mysql.com/doc/refman/%35%2E%31/en/non-typed-operators.html"><span style="color: #CC0099; font-weight: bold;">NOT</span></a> <a href="http://search.mysql.com/search?site=refman-%35%31&amp;q=NULL"><span style="color: #9900FF; font-weight: bold;">NULL</span></a><span style="color: #000033;">,</span>
  <span style="color: #008000;">`foreign<span style="color: #008080; font-weight: bold;">_</span>key`</span> <a href="http://search.mysql.com/search?site=refman-%35%31&amp;q=INT"><span style="color: #999900; font-weight: bold;">int</span></a><span style="color: #FF00FF;">&#40;</span><span style="color: #008080;">10</span><span style="color: #FF00FF;">&#41;</span> <a href="http://dev.mysql.com/doc/refman/%35%2E%31/en/non-typed-operators.html"><span style="color: #CC0099; font-weight: bold;">NOT</span></a> <a href="http://search.mysql.com/search?site=refman-%35%31&amp;q=NULL"><span style="color: #9900FF; font-weight: bold;">NULL</span></a><span style="color: #000033;">,</span>
  <span style="color: #008000;">`field`</span> <a href="http://search.mysql.com/search?site=refman-%35%31&amp;q=VARCHAR"><span style="color: #999900; font-weight: bold;">varchar</span></a><span style="color: #FF00FF;">&#40;</span><span style="color: #008080;">255</span><span style="color: #FF00FF;">&#41;</span> CHARACTER <a href="http://search.mysql.com/search?site=refman-%35%31&amp;q=SET"><span style="color: #990099; font-weight: bold;">SET</span></a> utf8 <a href="http://dev.mysql.com/doc/refman/%35%2E%31/en/non-typed-operators.html"><span style="color: #CC0099; font-weight: bold;">NOT</span></a> <a href="http://search.mysql.com/search?site=refman-%35%31&amp;q=NULL"><span style="color: #9900FF; font-weight: bold;">NULL</span></a><span style="color: #000033;">,</span>
  <span style="color: #008000;">`content`</span> <a href="http://search.mysql.com/search?site=refman-%35%31&amp;q=MEDIUMTEXT"><span style="color: #999900; font-weight: bold;">mediumtext</span></a> CHARACTER <a href="http://search.mysql.com/search?site=refman-%35%31&amp;q=SET"><span style="color: #990099; font-weight: bold;">SET</span></a> utf8<span style="color: #000033;">,</span>
  <a href="http://search.mysql.com/search?site=refman-%35%31&amp;q=PRIMARY%20KEY"><span style="color: #990099; font-weight: bold;">PRIMARY KEY</span></a> <span style="color: #FF00FF;">&#40;</span><span style="color: #008000;">`id`</span><span style="color: #FF00FF;">&#41;</span><span style="color: #000033;">,</span>
  <a href="http://search.mysql.com/search?site=refman-%35%31&amp;q=KEY"><span style="color: #990099; font-weight: bold;">KEY</span></a> <span style="color: #008000;">`locale`</span> <span style="color: #FF00FF;">&#40;</span><span style="color: #008000;">`locale`</span><span style="color: #FF00FF;">&#41;</span><span style="color: #000033;">,</span>
  <a href="http://search.mysql.com/search?site=refman-%35%31&amp;q=KEY"><span style="color: #990099; font-weight: bold;">KEY</span></a> <span style="color: #008000;">`model`</span> <span style="color: #FF00FF;">&#40;</span><span style="color: #008000;">`model`</span><span style="color: #FF00FF;">&#41;</span><span style="color: #000033;">,</span>
  <a href="http://search.mysql.com/search?site=refman-%35%31&amp;q=KEY"><span style="color: #990099; font-weight: bold;">KEY</span></a> <span style="color: #008000;">`row<span style="color: #008080; font-weight: bold;">_</span>id`</span> <span style="color: #FF00FF;">&#40;</span><span style="color: #008000;">`foreign<span style="color: #008080; font-weight: bold;">_</span>key`</span><span style="color: #FF00FF;">&#41;</span><span style="color: #000033;">,</span>
  <a href="http://search.mysql.com/search?site=refman-%35%31&amp;q=KEY"><span style="color: #990099; font-weight: bold;">KEY</span></a> <span style="color: #008000;">`field`</span> <span style="color: #FF00FF;">&#40;</span><span style="color: #008000;">`field`</span><span style="color: #FF00FF;">&#41;</span>
<span style="color: #FF00FF;">&#41;</span> <a href="http://search.mysql.com/search?site=refman-%35%31&amp;q=ENGINE"><span style="color: #990099; font-weight: bold;">ENGINE</span></a><span style="color: #CC0099;">=</span>MyISAM</pre></td></tr></table></div>

<p><strong>2. Khai báo xử dụng behavior Translate</strong></p>
<p>- Mình dùng lại database của bài: Tạo danh mục đa cấp, bạn nào chưa đọc thì đọc trước để lấy thông tin về ứng dụng mình đang demo nhé</p>
<p>- Các bạn xoá cột name trong bảng product_categories đi nhé!</p>
<p>- Mở file app/models/product_category.php, khai báo:</p>

<div class="wp_codebox"><table><tr id="p42450"><td class="code" id="p424code50"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">var</span> <span style="color: #000088;">$actsAs</span> <span style="color: #339933;">=</span> <a href="http://www.php.net/array"><span style="color: #990000;">array</span></a><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Tree'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'Translate'</span><span style="color: #339933;">=&gt;</span>array<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'name'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<p>- Trong đó:</p>
<p>+ Tree: dùng tạo danh mục đa cấp (đã nói trong chủ đề khác)<br />
+ Translate: giúp xây dựng nội dung đa ngôn ngữ</p>
<p>- Có bao nhiêu field cần làm đa ngôn ngữ thì các bạn khai báo hết vào mảng, dạng như:</p>

<div class="wp_codebox"><table><tr id="p42451"><td class="code" id="p424code51"><pre class="php" style="font-family:monospace;"><span style="color: #0000ff;">'Translate'</span> <span style="color: #339933;">=&gt;</span> <a href="http://www.php.net/array"><span style="color: #990000;">array</span></a><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'field_name_1'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'field_name_2'</span><span style="color: #339933;">,</span> <span style="color: #339933;">...</span><span style="color: #009900;">&#41;</span></pre></td></tr></table></div>

<p>Ở đây, danh mục chỉ có cột name cần làm đa ngôn ngữ nên mình khai báo:</p>

<div class="wp_codebox"><table><tr id="p42452"><td class="code" id="p424code52"><pre class="php" style="font-family:monospace;"><span style="color: #0000ff;">'Translate'</span> <span style="color: #339933;">=&gt;</span> <a href="http://www.php.net/array"><span style="color: #990000;">array</span></a><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'name'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<p><strong>3. Tạo hàm thiết lập ngôn ngữ cho model</strong></p>
<p>- Mở app/app_model.php, thêm vào hàm:</p>

<div class="wp_codebox"><table><tr id="p42453"><td class="code" id="p424code53"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">function</span> setLanguage<span style="color: #009900;">&#40;</span><span style="color: #000088;">$locale</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">locale</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$locale</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p><strong>4. View/Insert/Update dữ liệu</strong></p>
<p>- Ở mỗi action (view list, insert, update&#8230;), bạn cần thao tác dữ liệu ở dạng ngôn ngữ nào thì dùng:</p>

<div class="wp_codebox"><table><tr id="p42454"><td class="code" id="p424code54"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">ProductCategory</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">setLanguage</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$lang</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<p>Hoặc:</p>

<div class="wp_codebox"><table><tr id="p42455"><td class="code" id="p424code55"><pre class="php" style="font-family:monospace;">Configure<span style="color: #339933;">::</span><span style="color: #004000;">write</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Config.language'</span><span style="color: #339933;">,</span> <span style="color: #000088;">$lang</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<p>Trong đó, $lang là mã ngôn ngữ (Tiếng Việt: vie; Tiếng Anh: eng)</p>
<p>Các bạn xem mã này:</p>

<div class="wp_codebox"><table><tr id="p42456"><td class="code" id="p424code56"><pre class="php" style="font-family:monospace;"><a href="http://www.php.net/array"><span style="color: #990000;">array</span></a><span style="color: #009900;">&#40;</span><span style="color: #666666; font-style: italic;">/* Afrikaans */</span> <span style="color: #0000ff;">'afr'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'af'</span><span style="color: #339933;">,</span>
                                <span style="color: #666666; font-style: italic;">/* Albanian */</span> <span style="color: #0000ff;">'alb'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'sq'</span><span style="color: #339933;">,</span>
                                <span style="color: #666666; font-style: italic;">/* Arabic */</span> <span style="color: #0000ff;">'ara'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'ar'</span><span style="color: #339933;">,</span>
                                <span style="color: #666666; font-style: italic;">/* Armenian - Armenia */</span> <span style="color: #0000ff;">'hye'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'hy'</span><span style="color: #339933;">,</span>
                                <span style="color: #666666; font-style: italic;">/* Basque */</span> <span style="color: #0000ff;">'baq'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'eu'</span><span style="color: #339933;">,</span>
                                <span style="color: #666666; font-style: italic;">/* Bosnian */</span> <span style="color: #0000ff;">'bos'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'bs'</span><span style="color: #339933;">,</span>
                                <span style="color: #666666; font-style: italic;">/* Bulgarian */</span> <span style="color: #0000ff;">'bul'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'bg'</span><span style="color: #339933;">,</span>
                                <span style="color: #666666; font-style: italic;">/* Byelorussian */</span> <span style="color: #0000ff;">'bel'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'be'</span><span style="color: #339933;">,</span>
                                <span style="color: #666666; font-style: italic;">/* Catalan */</span> <span style="color: #0000ff;">'cat'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'ca'</span><span style="color: #339933;">,</span>
                                <span style="color: #666666; font-style: italic;">/* Chinese */</span> <span style="color: #0000ff;">'chi'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'zh'</span><span style="color: #339933;">,</span>
                                <span style="color: #666666; font-style: italic;">/* Chinese */</span> <span style="color: #0000ff;">'zho'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'zh'</span><span style="color: #339933;">,</span>
                                <span style="color: #666666; font-style: italic;">/* Croatian */</span> <span style="color: #0000ff;">'hrv'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'hr'</span><span style="color: #339933;">,</span>
                                <span style="color: #666666; font-style: italic;">/* Czech */</span> <span style="color: #0000ff;">'cze'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'cs'</span><span style="color: #339933;">,</span>
                                <span style="color: #666666; font-style: italic;">/* Czech */</span> <span style="color: #0000ff;">'ces'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'cs'</span><span style="color: #339933;">,</span>
                                <span style="color: #666666; font-style: italic;">/* Danish */</span> <span style="color: #0000ff;">'dan'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'da'</span><span style="color: #339933;">,</span>
                                <span style="color: #666666; font-style: italic;">/* Dutch (Standard) */</span> <span style="color: #0000ff;">'dut'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'nl'</span><span style="color: #339933;">,</span>
                                <span style="color: #666666; font-style: italic;">/* Dutch (Standard) */</span> <span style="color: #0000ff;">'nld'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'nl'</span><span style="color: #339933;">,</span>
                                <span style="color: #666666; font-style: italic;">/* English */</span> <span style="color: #0000ff;">'eng'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'en'</span><span style="color: #339933;">,</span>
                                <span style="color: #666666; font-style: italic;">/* Estonian */</span> <span style="color: #0000ff;">'est'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'et'</span><span style="color: #339933;">,</span>
                                <span style="color: #666666; font-style: italic;">/* Faeroese */</span> <span style="color: #0000ff;">'fao'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'fo'</span><span style="color: #339933;">,</span>
                                <span style="color: #666666; font-style: italic;">/* Farsi */</span> <span style="color: #0000ff;">'fas'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'fa'</span><span style="color: #339933;">,</span>
                                <span style="color: #666666; font-style: italic;">/* Farsi */</span> <span style="color: #0000ff;">'per'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'fa'</span><span style="color: #339933;">,</span>
                                <span style="color: #666666; font-style: italic;">/* Finnish */</span> <span style="color: #0000ff;">'fin'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'fi'</span><span style="color: #339933;">,</span>
                                <span style="color: #666666; font-style: italic;">/* French (Standard) */</span> <span style="color: #0000ff;">'fre'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'fr'</span><span style="color: #339933;">,</span>
                                <span style="color: #666666; font-style: italic;">/* French (Standard) */</span> <span style="color: #0000ff;">'fra'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'fr'</span><span style="color: #339933;">,</span>
                                <span style="color: #666666; font-style: italic;">/* Gaelic (Scots) */</span> <span style="color: #0000ff;">'gla'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'gd'</span><span style="color: #339933;">,</span>
                                <span style="color: #666666; font-style: italic;">/* Galician */</span> <span style="color: #0000ff;">'glg'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'gl'</span><span style="color: #339933;">,</span>
                                <span style="color: #666666; font-style: italic;">/* German (Standard) */</span> <span style="color: #0000ff;">'deu'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'de'</span><span style="color: #339933;">,</span>
                                <span style="color: #666666; font-style: italic;">/* German (Standard) */</span> <span style="color: #0000ff;">'ger'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'de'</span><span style="color: #339933;">,</span>
                                <span style="color: #666666; font-style: italic;">/* Greek */</span> <span style="color: #0000ff;">'gre'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'el'</span><span style="color: #339933;">,</span>
                                <span style="color: #666666; font-style: italic;">/* Greek */</span> <span style="color: #0000ff;">'ell'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'el'</span><span style="color: #339933;">,</span>
                                <span style="color: #666666; font-style: italic;">/* Hebrew */</span> <span style="color: #0000ff;">'heb'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'he'</span><span style="color: #339933;">,</span>
                                <span style="color: #666666; font-style: italic;">/* Hindi */</span> <span style="color: #0000ff;">'hin'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'hi'</span><span style="color: #339933;">,</span>
                                <span style="color: #666666; font-style: italic;">/* Hungarian */</span> <span style="color: #0000ff;">'hun'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'hu'</span><span style="color: #339933;">,</span>
                                <span style="color: #666666; font-style: italic;">/* Icelandic */</span> <span style="color: #0000ff;">'ice'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'is'</span><span style="color: #339933;">,</span>
                                <span style="color: #666666; font-style: italic;">/* Icelandic */</span> <span style="color: #0000ff;">'isl'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'is'</span><span style="color: #339933;">,</span>
                                <span style="color: #666666; font-style: italic;">/* Indonesian */</span> <span style="color: #0000ff;">'ind'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'id'</span><span style="color: #339933;">,</span>
                                <span style="color: #666666; font-style: italic;">/* Irish */</span> <span style="color: #0000ff;">'gle'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'ga'</span><span style="color: #339933;">,</span>
                                <span style="color: #666666; font-style: italic;">/* Italian */</span> <span style="color: #0000ff;">'ita'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'it'</span><span style="color: #339933;">,</span>
                                <span style="color: #666666; font-style: italic;">/* Japanese */</span> <span style="color: #0000ff;">'jpn'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'ja'</span><span style="color: #339933;">,</span>
                                <span style="color: #666666; font-style: italic;">/* Korean */</span> <span style="color: #0000ff;">'kor'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'ko'</span><span style="color: #339933;">,</span>
                                <span style="color: #666666; font-style: italic;">/* Latvian */</span> <span style="color: #0000ff;">'lav'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'lv'</span><span style="color: #339933;">,</span>
                                <span style="color: #666666; font-style: italic;">/* Lithuanian */</span> <span style="color: #0000ff;">'lit'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'lt'</span><span style="color: #339933;">,</span>
                                <span style="color: #666666; font-style: italic;">/* Macedonian */</span> <span style="color: #0000ff;">'mac'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'mk'</span><span style="color: #339933;">,</span>
                                <span style="color: #666666; font-style: italic;">/* Macedonian */</span> <span style="color: #0000ff;">'mkd'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'mk'</span><span style="color: #339933;">,</span>
                                <span style="color: #666666; font-style: italic;">/* Malaysian */</span> <span style="color: #0000ff;">'may'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'ms'</span><span style="color: #339933;">,</span>
                                <span style="color: #666666; font-style: italic;">/* Malaysian */</span> <span style="color: #0000ff;">'msa'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'ms'</span><span style="color: #339933;">,</span>
                                <span style="color: #666666; font-style: italic;">/* Maltese */</span> <span style="color: #0000ff;">'mlt'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'mt'</span><span style="color: #339933;">,</span>
                                <span style="color: #666666; font-style: italic;">/* Norwegian */</span> <span style="color: #0000ff;">'nor'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'no'</span><span style="color: #339933;">,</span>
                                <span style="color: #666666; font-style: italic;">/* Norwegian Bokmal */</span> <span style="color: #0000ff;">'nob'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'nb'</span><span style="color: #339933;">,</span>
                                <span style="color: #666666; font-style: italic;">/* Norwegian Nynorsk */</span> <span style="color: #0000ff;">'nno'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'nn'</span><span style="color: #339933;">,</span>
                                <span style="color: #666666; font-style: italic;">/* Polish */</span> <span style="color: #0000ff;">'pol'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'pl'</span><span style="color: #339933;">,</span>
                                <span style="color: #666666; font-style: italic;">/* Portuguese (Portugal) */</span> <span style="color: #0000ff;">'por'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'pt'</span><span style="color: #339933;">,</span>
                                <span style="color: #666666; font-style: italic;">/* Rhaeto-Romanic */</span> <span style="color: #0000ff;">'roh'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'rm'</span><span style="color: #339933;">,</span>
                                <span style="color: #666666; font-style: italic;">/* Romanian */</span> <span style="color: #0000ff;">'rum'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'ro'</span><span style="color: #339933;">,</span>
                                <span style="color: #666666; font-style: italic;">/* Romanian */</span> <span style="color: #0000ff;">'ron'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'ro'</span><span style="color: #339933;">,</span>
                                <span style="color: #666666; font-style: italic;">/* Russian */</span> <span style="color: #0000ff;">'rus'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'ru'</span><span style="color: #339933;">,</span>
                                <span style="color: #666666; font-style: italic;">/* Sami (Lappish) */</span> <span style="color: #0000ff;">'smi'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'sz'</span><span style="color: #339933;">,</span>
                                <span style="color: #666666; font-style: italic;">/* Serbian */</span> <span style="color: #0000ff;">'scc'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'sr'</span><span style="color: #339933;">,</span>
                                <span style="color: #666666; font-style: italic;">/* Serbian */</span> <span style="color: #0000ff;">'srp'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'sr'</span><span style="color: #339933;">,</span>
                                <span style="color: #666666; font-style: italic;">/* Slovak */</span> <span style="color: #0000ff;">'slo'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'sk'</span><span style="color: #339933;">,</span>
                                <span style="color: #666666; font-style: italic;">/* Slovak */</span> <span style="color: #0000ff;">'slk'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'sk'</span><span style="color: #339933;">,</span>
                                <span style="color: #666666; font-style: italic;">/* Slovenian */</span> <span style="color: #0000ff;">'slv'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'sl'</span><span style="color: #339933;">,</span>
                                <span style="color: #666666; font-style: italic;">/* Sorbian */</span> <span style="color: #0000ff;">'wen'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'sb'</span><span style="color: #339933;">,</span>
                                <span style="color: #666666; font-style: italic;">/* Spanish (Spain - Traditional) */</span> <span style="color: #0000ff;">'spa'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'es'</span><span style="color: #339933;">,</span>
                                <span style="color: #666666; font-style: italic;">/* Swedish */</span> <span style="color: #0000ff;">'swe'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'sv'</span><span style="color: #339933;">,</span>
                                <span style="color: #666666; font-style: italic;">/* Thai */</span> <span style="color: #0000ff;">'tha'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'th'</span><span style="color: #339933;">,</span>
                                <span style="color: #666666; font-style: italic;">/* Tsonga */</span> <span style="color: #0000ff;">'tso'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'ts'</span><span style="color: #339933;">,</span>
                                <span style="color: #666666; font-style: italic;">/* Tswana */</span> <span style="color: #0000ff;">'tsn'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'tn'</span><span style="color: #339933;">,</span>
                                <span style="color: #666666; font-style: italic;">/* Turkish */</span> <span style="color: #0000ff;">'tur'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'tr'</span><span style="color: #339933;">,</span>
                                <span style="color: #666666; font-style: italic;">/* Ukrainian */</span> <span style="color: #0000ff;">'ukr'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'uk'</span><span style="color: #339933;">,</span>
                                <span style="color: #666666; font-style: italic;">/* Urdu */</span> <span style="color: #0000ff;">'urd'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'ur'</span><span style="color: #339933;">,</span>
                                <span style="color: #666666; font-style: italic;">/* Venda */</span> <span style="color: #0000ff;">'ven'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'ve'</span><span style="color: #339933;">,</span>
                                <span style="color: #666666; font-style: italic;">/* Vietnamese */</span> <span style="color: #0000ff;">'vie'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'vi'</span><span style="color: #339933;">,</span>
                                <span style="color: #666666; font-style: italic;">/* Welsh */</span> <span style="color: #0000ff;">'cym'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'cy'</span><span style="color: #339933;">,</span>
                                <span style="color: #666666; font-style: italic;">/* Xhosa */</span> <span style="color: #0000ff;">'xho'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'xh'</span><span style="color: #339933;">,</span>
                                <span style="color: #666666; font-style: italic;">/* Yiddish */</span> <span style="color: #0000ff;">'yid'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'yi'</span><span style="color: #339933;">,</span>
                                <span style="color: #666666; font-style: italic;">/* Zulu */</span> <span style="color: #0000ff;">'zul'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'zu'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<p>Như vậy là xong, nếu làm đúng, dữ liệu bảng i18n khi show lên sẽ có dạng:</p>
<p>+&#8212;-+&#8212;&#8212;&#8211;+&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;+&#8212;&#8212;&#8212;&#8212;-+&#8212;&#8212;-+&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;+<br />
| id | locale | model | foreign_key | field | content |<br />
+&#8212;-+&#8212;&#8212;&#8211;+&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;+&#8212;&#8212;&#8212;&#8212;-+&#8212;&#8212;-+&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;+<br />
| 1 | vie | ProductCategory | 2 | name | Thiết bị mạng |<br />
| 2 | eng | ProductCategory | 3 | name | Network Devices |<br />
| 3 | vie | ProductCategory | 4 | name | Máy chủ |<br />
| 4 | eng | ProductCategory | 5 | name | Server |<br />
+&#8212;-+&#8212;&#8212;&#8211;+&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;+&#8212;&#8212;&#8212;&#8212;-+&#8212;&#8212;-+&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;+</p>
<p><strong>5. Lưu trữ dữ liệu đa ngôn ngữ trên nhiều table</strong></p>
<p>- Với cách lưu toàn bộ dữ liệu đa ngôn ngữ và bảng i18n sẽ có nhược điểm:</p>
<p>+ Kích thước table i18n quá nặng<br />
+ Nếu dữ liệu bị hư hoặc cần điều chỉnh tay, thao tác trên 1 table dữ liệu lớn sẽ không thuận lợi</p>
<p>- Do đó, CakePHP cho phép chúng ta chỉ định cho model table nào chứa dữ liệu đa ngôn ngữ</p>
<p>- Cách làm:</p>
<p><strong>5.1. Tạo table chứa dữ liệu đa ngôn ngữ</strong></p>
<p>- Cũng dùng cấu trúc như i18n nhưng đổi tên table</p>
<p><strong>5.2. Tạo model cho bảng dữ liệu đa ngôn ngữ</strong></p>
<p>- Tạo app/models/product_category_language.php có nội dung:</p>

<div class="wp_codebox"><table><tr id="p42457"><td class="code" id="p424code57"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">class</span> ProductCategoryTranslation <span style="color: #000000; font-weight: bold;">extends</span> AppModel <span style="color: #009900;">&#123;</span> 
    <span style="color: #000000; font-weight: bold;">var</span> <span style="color: #000088;">$displayField</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'field'</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p>- Chú ý, phải có <strong>$displayField</strong> là tên &#8216;<strong>field</strong>&#8216; vì mặc định Cake sẽ dùng cột có tên name hoặc title để lấy trong hàm find(&#8216;list&#8217;);</p>
<p><strong>5.3. Edit model gốc</strong></p>
<p>- Thêm 2 khai báo vào app/models/product_category.php</p>

<div class="wp_codebox"><table><tr id="p42458"><td class="code" id="p424code58"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">var</span> <span style="color: #000088;">$translateModel</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'ProductCategoryTranslation'</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">var</span> <span style="color: #000088;">$translateTable</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'product_category_translations'</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<p>- Lưu ý: <strong>$translateTable</strong> phải đi chung với <strong>$translateModel</strong></p>
<p>Như vậy là xong, kể từ thời điểm này, dữ liệu thêm mới sẽ vào bảng product_category_translations thay vì i18n</p>
<p><strong>6. Tạo form chuyển đổi ngôn ngữ</strong></p>
<p>- Về mặt cấu trúc là tạm ổn, còn phần khá quan trọng là làm form chuyển đổi ngôn ngữ. Các bạn có thể làm theo cách:</p>
<p>+ Chọn ngôn ngữ trước khi vào admin: đây là cách làm dễ nhất, nhưng như vậy 1 record tiếng này sẽ không thể tương ứng với 1 record tiếng khác, khi chuyển ngôn ngữ sẽ phải quay về trang chủ<br />
+ Trên trang list, các bạn làm 1 nút chuyển ngôn ngữ, khi sang form update, các bạn giữ lại id của record mới nhấn, khi save dữ liệu, chỉ có bảng product_category_translation có record mới, còn bảng product_categories sẽ đảm bảo chỉ có 1 record</p>
<p><strong>7. Tải source</strong></p>
<p>- Các bạn tải source chứa cả phần tree và translate bên dưới:</p>
<p>http://www.mediafire.com/?n6s236v10a5cvny</p>
<p>- Pass giải nén: cakephpvn.org</p>
<p>- Lưu ý: source ko có thư viện cake nên không thể chạy trực tiếp, muốn chạy trực tiếp thì mở webroot/index.php trỏ lại path tới lib của cake nhé!</p>
]]></content:encoded>
			<wfw:commentRss>http://cakephpvn.org/index.php/2010/11/21/lam-site-da-ngon-ngu-voi-cakephp-phan-1/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>CakePHP 1.3.6 and 1.2.9 released</title>
		<link>http://cakephpvn.org/index.php/2010/11/17/cakephp-1-3-6-and-1-2-9-released/</link>
		<comments>http://cakephpvn.org/index.php/2010/11/17/cakephp-1-3-6-and-1-2-9-released/#comments</comments>
		<pubDate>Wed, 17 Nov 2010 14:56:48 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Phiên bản]]></category>
		<category><![CDATA[1.2.9]]></category>
		<category><![CDATA[1.3.6]]></category>

		<guid isPermaLink="false">http://cakephpvn.org/?p=421</guid>
		<description><![CDATA[The CakePHP core team is proud to announce the immediate availability of CakePHP 1.3.6 and 1.2.9. These releases are recommended for all users as they fix a security issue. Since the release CakePHP 1.3.5 less a month ago, there have been over 25 commits[1] and 10 tickets resolved. The 1.2 branch has 20 commits[2] and [...]]]></description>
			<content:encoded><![CDATA[<p>The CakePHP core team is proud to announce the immediate availability of CakePHP 1.3.6 and 1.2.9. These releases are recommended for all users as they fix a security issue. Since the release CakePHP 1.3.5 less a month ago, there have been over 25 commits[1] and 10 tickets resolved. The 1.2 branch has 20 commits[2] and 15 tickets resolved, since the release of 1.2.8 in August.<br />
<span id="more-421"></span></p>
<p>The CakePHP core team is proud to announce the immediate availability of CakePHP 1.3.6 and 1.2.9. These releases are recommended for all users as they fix a security issue. Since the release CakePHP 1.3.5 less a month ago, there have been over 25 commits[1] and 10 tickets resolved. The 1.2 branch has 20 commits[2] and 15 tickets resolved, since the release of 1.2.8 in August. There have been a few changes that may affect your application in each version:</p>
<p>1.3</p>
<p>CakeSchema::compare() now better handles comparing &#8221; and null.<br />
NumberHelper::currency() better formats € amounts of less than 1.0.<br />
Race conditions in Model::delete() were fixed, so deletions only occur for the specified record.<br />
A security issue in SecurityComponent was fixed.</p>
<p>1.2</p>
<p>Race conditions in Model::delete() were fixed, so deletions only occur for the specified record.<br />
A security issue in SecurityComponent was fixed.<br />
SecurityComponent and digest auth work correctly with email address usernames.<br />
EmailComponent now more correctly handles email addresses with name aliases<br />
These releases are recommended for all users, as they include a fix for a </p>
]]></content:encoded>
			<wfw:commentRss>http://cakephpvn.org/index.php/2010/11/17/cakephp-1-3-6-and-1-2-9-released/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

