<?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>No Meaning Developer &#187; PHP</title>
	<atom:link href="http://kentreez.com/blog/category/php/feed/" rel="self" type="application/rss+xml" />
	<link>http://kentreez.com/blog</link>
	<description>kentreez&#039;s blog</description>
	<lastBuildDate>Tue, 05 Jul 2011 16:13:36 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
		<item>
		<title>function php ที่ไม่ค่อยได้ใช้ เก็บไว้เผื่อลืม</title>
		<link>http://kentreez.com/blog/php/function-php-%e0%b8%97%e0%b8%b5%e0%b9%88%e0%b9%84%e0%b8%a1%e0%b9%88%e0%b8%84%e0%b9%88%e0%b8%ad%e0%b8%a2%e0%b9%84%e0%b8%94%e0%b9%89%e0%b9%83%e0%b8%8a%e0%b9%89-%e0%b9%80%e0%b8%81%e0%b9%87%e0%b8%9a/</link>
		<comments>http://kentreez.com/blog/php/function-php-%e0%b8%97%e0%b8%b5%e0%b9%88%e0%b9%84%e0%b8%a1%e0%b9%88%e0%b8%84%e0%b9%88%e0%b8%ad%e0%b8%a2%e0%b9%84%e0%b8%94%e0%b9%89%e0%b9%83%e0%b8%8a%e0%b9%89-%e0%b9%80%e0%b8%81%e0%b9%87%e0%b8%9a/#comments</comments>
		<pubDate>Wed, 24 Nov 2010 09:21:26 +0000</pubDate>
		<dc:creator>kentreez</dc:creator>
				<category><![CDATA[PHP]]></category>

		<guid isPermaLink="false">http://kentreez.com/blog/?p=271</guid>
		<description><![CDATA[imap_mime_header_decode]]></description>
			<content:encoded><![CDATA[<ul>
<li><a href="http://php.net/manual/en/function.imap-mime-header-decode.php">imap_mime_header_decode</a></li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://kentreez.com/blog/php/function-php-%e0%b8%97%e0%b8%b5%e0%b9%88%e0%b9%84%e0%b8%a1%e0%b9%88%e0%b8%84%e0%b9%88%e0%b8%ad%e0%b8%a2%e0%b9%84%e0%b8%94%e0%b9%89%e0%b9%83%e0%b8%8a%e0%b9%89-%e0%b9%80%e0%b8%81%e0%b9%87%e0%b8%9a/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>How to enable using the $_GET variable in CodeIgniter</title>
		<link>http://kentreez.com/blog/php/solutions/how-to-enable-using-the-_get-variable-in-codeigniter/</link>
		<comments>http://kentreez.com/blog/php/solutions/how-to-enable-using-the-_get-variable-in-codeigniter/#comments</comments>
		<pubDate>Sat, 01 Nov 2008 06:44:58 +0000</pubDate>
		<dc:creator>kentreez</dc:creator>
				<category><![CDATA[CodeIgniter]]></category>
		<category><![CDATA[Solutions]]></category>

		<guid isPermaLink="false">http://journal.kentreez.com/?p=82</guid>
		<description><![CDATA[คงจะทราบดีว่า ถ้าเราตั้ง $config['enable_query_strings'] = FALSE ตัว CodeIgniter มันจะ unset ตัวแปร $_GET ของเราซะงั้น  ครั้งแรกที่ผมแก้ ผมเข้าไปแก้ที่ core ของ CodeIgniter เลยครับ  แต่วันนี้ผมคิดเทคนิคดีๆ ได้แล้ว เลยอยากบอกต่อครับ ให้เข้าไปตั้งค่าในไฟล์ config.php ดังนี้ครับ $config['permitted_uri_chars'] = ''; $config['enable_query_strings'] = TRUE; $config['controller_trigger'] = "adl3q-gSF3_QklAWq"; // &#60;-- ใส่ค่าอะไรก็ได้ ที่คิดว่าไม่มีใครเดาออกชัวๆ $config['function_trigger'] = "oIUgk42__mA-2v04"; // &#60;-- ใส่ค่าอะไรก็ได้ ที่คิดว่าไม่มีใครเดาออกชัวๆ เท่านี้ก็เรียบร้อยครับ คราวนี้ก็สามารถทำอะไรลักษณะนี้ได้แล้วครับ http://localhost/controllerA/method/?a=1&#38;b=2&#38;c=3 Awesome~!]]></description>
			<content:encoded><![CDATA[<p>คงจะทราบดีว่า ถ้าเราตั้ง $config['enable_query_strings'] = FALSE ตัว CodeIgniter มันจะ unset ตัวแปร $_GET ของเราซะงั้น  ครั้งแรกที่ผมแก้ ผมเข้าไปแก้ที่ core ของ CodeIgniter เลยครับ  แต่วันนี้ผมคิดเทคนิคดีๆ ได้แล้ว เลยอยากบอกต่อครับ</p>
<p>ให้เข้าไปตั้งค่าในไฟล์ <strong>config.php</strong> ดังนี้ครับ</p>
<p><span id="more-82"></span></p>
<p><code><br />
$config['permitted_uri_chars'] = '';<br />
$config['enable_query_strings'] = TRUE;<br />
$config['controller_trigger'] = "adl3q-gSF3_QklAWq"; // &lt;--  ใส่ค่าอะไรก็ได้ ที่คิดว่าไม่มีใครเดาออกชัวๆ<br />
$config['function_trigger'] = "oIUgk42__mA-2v04"; // &lt;--  ใส่ค่าอะไรก็ได้ ที่คิดว่าไม่มีใครเดาออกชัวๆ<br />
</code></p>
<p>เท่านี้ก็เรียบร้อยครับ</p>
<p>คราวนี้ก็สามารถทำอะไรลักษณะนี้ได้แล้วครับ</p>
<p><strong>http://localhost/controllerA/method/?a=1&amp;b=2&amp;c=3</strong></p>
<p>Awesome~!</p>
]]></content:encoded>
			<wfw:commentRss>http://kentreez.com/blog/php/solutions/how-to-enable-using-the-_get-variable-in-codeigniter/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Wick 0.8 just another bug</title>
		<link>http://kentreez.com/blog/php/wick-08-just-another-bug/</link>
		<comments>http://kentreez.com/blog/php/wick-08-just-another-bug/#comments</comments>
		<pubDate>Sat, 26 Jul 2008 15:54:32 +0000</pubDate>
		<dc:creator>kentreez</dc:creator>
				<category><![CDATA[CodeIgniter]]></category>
		<category><![CDATA[Notice]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Wick0.8]]></category>

		<guid isPermaLink="false">http://journal.kentreez.com/?p=75</guid>
		<description><![CDATA[สำหรับปัญหาล่าสุดที่เจอ จะอยู่ในส่วนของ Router ครับ ซึ่งมีตัวแปรหลายตัวที่ไม่ถูก Reset ค่าทำให้เกิดข้อผิดพลาดมากมายในการ Load Controller ตัวถัดมาครับ.  ตรงนี้ผมแก้โดยใช้เก็บค่าก่อน Load Controller ลง Stack ไว้ก่อนครับ. แล้วก็ดึงคืนเวลาโหลดเสร็จครับ. Wick0.8 ยังไม่เหมาะที่จะนำมาใช้งานจริงอย่างยิ่งครับ  หลังจากที่ค่อยๆ ปรับแก้ ไปเรื่อยๆ ก็จะมีปัญหาใหม่ๆ เกิดขึ้นเรื่อยๆ เช่นกัน.  สำหรับนักพัฒนาท่านใดที่คิดจะใช้เจ้าตัวนี้ ขอให้ลองคิดหาทางเลือกอื่นก่อนจะดีกว่านะครับ  ไม่งั้นท่านต้องเสียเวลาในการปรับปรุงเฟรมเวิคเยอะครับ  ดีไม่ดีเยอะกว่าเวลาที่ใช้ทำงานหลักจริงๆ เสียอีกนะครับ.   สำหรับผมถอยไม่ได้แล้วครับ  ยังไงก็จะลุยต่อครับ.]]></description>
			<content:encoded><![CDATA[<p>สำหรับปัญหาล่าสุดที่เจอ จะอยู่ในส่วนของ Router ครับ ซึ่งมีตัวแปรหลายตัวที่ไม่ถูก Reset ค่าทำให้เกิดข้อผิดพลาดมากมายในการ Load Controller ตัวถัดมาครับ.  ตรงนี้ผมแก้โดยใช้เก็บค่าก่อน Load Controller ลง Stack ไว้ก่อนครับ. แล้วก็ดึงคืนเวลาโหลดเสร็จครับ.</p>
<blockquote><p>Wick0.8 ยังไม่เหมาะที่จะนำมาใช้งานจริงอย่างยิ่งครับ  หลังจากที่ค่อยๆ ปรับแก้ ไปเรื่อยๆ ก็จะมีปัญหาใหม่ๆ เกิดขึ้นเรื่อยๆ เช่นกัน.  สำหรับนักพัฒนาท่านใดที่คิดจะใช้เจ้าตัวนี้ ขอให้ลองคิดหาทางเลือกอื่นก่อนจะดีกว่านะครับ  ไม่งั้นท่านต้องเสียเวลาในการปรับปรุงเฟรมเวิคเยอะครับ  ดีไม่ดีเยอะกว่าเวลาที่ใช้ทำงานหลักจริงๆ เสียอีกนะครับ.   สำหรับผมถอยไม่ได้แล้วครับ  ยังไงก็จะลุยต่อครับ.</p></blockquote>
]]></content:encoded>
			<wfw:commentRss>http://kentreez.com/blog/php/wick-08-just-another-bug/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Reset value of _fail_gracefully (avoid recursively call controller)</title>
		<link>http://kentreez.com/blog/php/reset-value-of-_fail_gracefully-avoid-recursively-call-controller/</link>
		<comments>http://kentreez.com/blog/php/reset-value-of-_fail_gracefully-avoid-recursively-call-controller/#comments</comments>
		<pubDate>Thu, 24 Jul 2008 08:06:48 +0000</pubDate>
		<dc:creator>kentreez</dc:creator>
				<category><![CDATA[CodeIgniter]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Solutions]]></category>

		<guid isPermaLink="false">http://journal.kentreez.com/?p=73</guid>
		<description><![CDATA[Wick Ref: http://codeigniter.com/wiki/Wick/ ผมเจอปัญหาว่าเวลามีการเรียก  $this-&#62;load-&#62;uri ( &#8230; ); ที่ไม่มีอยู่จริง ปรกติแล้วควรจะขึ้น Error ว่าไม่พบ Controller หรืออะไรประมาณนั้น แต่ปัญหาคือเมื่อเรียก controller ที่ไม่มีอยู่จริงแล้ว จะทำให้มันพยายาม load controller ตัวเดิมไปเรื่อยๆ แบบ Recusive.  คิดว่าน่าจะเกิดเฉพาะกรณีที่ คุณเข้าถึง controller หลักโดยไม่ได้ระบุ controller  (หมายถึง มันเข้า default controller) เพราะจะไปมีผลกับตัวแปร  _fail_gracefully ครับ ซึ่งจะกลายเป็น true เมื่อมีการดึง config ตรง default controller มาใช้. วิธีแก้ก็ไม่ยากครับ ตามข้างล่างเลย! /system/application/libraries/Wick.php]]></description>
			<content:encoded><![CDATA[<p>Wick Ref: <a href="http://codeigniter.com/wiki/Wick/" target="_blank">http://codeigniter.com/wiki/Wick/</a></p>
<p>ผมเจอปัญหาว่าเวลามีการเรียก  $this-&gt;load-&gt;uri ( &#8230; ); ที่ไม่มีอยู่จริง ปรกติแล้วควรจะขึ้น Error ว่าไม่พบ Controller หรืออะไรประมาณนั้น แต่ปัญหาคือเมื่อเรียก controller ที่ไม่มีอยู่จริงแล้ว จะทำให้มันพยายาม load controller ตัวเดิมไปเรื่อยๆ แบบ Recusive.  คิดว่าน่าจะเกิดเฉพาะกรณีที่ คุณเข้าถึง controller หลักโดยไม่ได้ระบุ controller  (หมายถึง มันเข้า default controller) เพราะจะไปมีผลกับตัวแปร  _fail_gracefully ครับ ซึ่งจะกลายเป็น <strong>true</strong> เมื่อมีการดึง config ตรง default controller มาใช้. วิธีแก้ก็ไม่ยากครับ ตามข้างล่างเลย!</p>
<p><strong><em>/system/application/libraries/Wick.php</em></strong></p>
<pre class="brush: php; title: ; notranslate">        $router = &amp;load_class('Router');
        $uricla = &amp;amp;load_class('URI');
        $router-&gt;_fail_gracefully = false; // &lt;-- Insert this Line
        $router-&gt;_set_request($uri);</pre>
]]></content:encoded>
			<wfw:commentRss>http://kentreez.com/blog/php/reset-value-of-_fail_gracefully-avoid-recursively-call-controller/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Wick 0.8 Bug with Model &amp; non-core Library</title>
		<link>http://kentreez.com/blog/php/wick-08-bug-with-model-non-core-library/</link>
		<comments>http://kentreez.com/blog/php/wick-08-bug-with-model-non-core-library/#comments</comments>
		<pubDate>Wed, 23 Jul 2008 19:12:21 +0000</pubDate>
		<dc:creator>kentreez</dc:creator>
				<category><![CDATA[Case Studies]]></category>
		<category><![CDATA[CodeIgniter]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Solutions]]></category>

		<guid isPermaLink="false">http://journal.kentreez.com/?p=69</guid>
		<description><![CDATA[Wick Ref: http://codeigniter.com/wiki/Wick/ หลังจากที่สู้รบปรบมือกับปัญหานี้อยู่นาน ผมก็เจอสาเหตุที่แท้จริงจนได้ครับ  และสามารถแก้ไขได้ด้วยครับ งานนี้ถึงเหนื่อยก็คุ้มครับ ปัญหา เมื่อมีการเรียก $this-&#62;load-&#62;uri( &#8230;. ); จะทำให้พวก Model และ Non-core Library หายไปครับ (อาจรวมไปถึง plugin ด้วย). บางคนอาจจะเข้าใจว่ามันไม่ถูกโหลดเข้าไปใน Controller ตัวที่ถูกเรียกเท่านั้น, แต่จริงๆ แล้วนอกจากจะไม่ถูกโหลดเข้าไปแล้ว ยังทำให้สิ่งเหล่านี้ที่อยู่ที่ Controller หลักหายไปด้วยครับ. ทำให้ไม่สามารถใช้งาน Model, Non-core Library และ Plugin ได้ตามปรกติ ถ้ามีการใช้งาน Load URI ของ Wick การหาสาเหตุ Debugger นี่แทบไม่ช่วยเลยครับ. อาจจะเป็นเพราะผมยังมือใหม่สำหรับการใช้งานตัว Debugger สุดท้ายเลยใช้วิธีดั้งเดิมครับ. หลังจากที่ลองไปหลายๆ รูปแบบ เพื่อตัดผู้ต้องสงสัยให้แคบลงมาหน่อย เพราะว่าผู้ต้องสงสัยตอนแรกนี่เยอะเหลือเกินครับ ผมถึงบอกว่า Debugger ไม่ช่วยก็เพราะยั่งงี้ครับ ไม่รู้จะไปจับดูตรงไหน [...]]]></description>
			<content:encoded><![CDATA[<p>Wick Ref: <a href="http://codeigniter.com/wiki/Wick/">http://codeigniter.com/wiki/Wick/</a></p>
<p>หลังจากที่สู้รบปรบมือกับปัญหานี้อยู่นาน ผมก็เจอสาเหตุที่แท้จริงจนได้ครับ  และสามารถแก้ไขได้ด้วยครับ งานนี้ถึงเหนื่อยก็คุ้มครับ</p>
<h3>ปัญหา</h3>
<blockquote><p>เมื่อมีการเรียก $this-&gt;load-&gt;uri( &#8230;. ); จะทำให้พวก Model และ Non-core Library หายไปครับ (อาจรวมไปถึง plugin ด้วย). บางคนอาจจะเข้าใจว่ามันไม่ถูกโหลดเข้าไปใน Controller ตัวที่ถูกเรียกเท่านั้น, แต่จริงๆ แล้วนอกจากจะไม่ถูกโหลดเข้าไปแล้ว ยังทำให้สิ่งเหล่านี้ที่อยู่ที่ Controller หลักหายไปด้วยครับ. ทำให้ไม่สามารถใช้งาน Model, Non-core Library และ Plugin ได้ตามปรกติ ถ้ามีการใช้งาน Load URI ของ Wick</p></blockquote>
<h3>การหาสาเหตุ</h3>
<blockquote><p>Debugger นี่แทบไม่ช่วยเลยครับ. อาจจะเป็นเพราะผมยังมือใหม่สำหรับการใช้งานตัว Debugger สุดท้ายเลยใช้วิธีดั้งเดิมครับ. หลังจากที่ลองไปหลายๆ รูปแบบ เพื่อตัดผู้ต้องสงสัยให้แคบลงมาหน่อย เพราะว่าผู้ต้องสงสัยตอนแรกนี่เยอะเหลือเกินครับ ผมถึงบอกว่า Debugger ไม่ช่วยก็เพราะยั่งงี้ครับ ไม่รู้จะไปจับดูตรงไหน จะไล่ดูก็ยากอีก.</p>
<p>ตอนแรกผมพยายามไล่ดูใน Wick ครับ เพราะเข้าใจว่า Wick คงโหลดบางอย่างไม่ครบ แต่ก็ไม่เจออะไรครับ เพราะพอหลังจากอ่านโค๊ดอยู่สักพัก ก็เข้าใจว่า Wick เป็นเพียง Library ที่มาเสริมโดยเพิ่ม method uri ใน Loader เฉยๆ ครับ. อย่างที่บอกครับว่าผมพบว่า Model และ Non-core Library มันหายไปจาก Controller หลักด้วย, เคสนี้เป็นเคสที่สำคัญเลยครับ เพราะใน Wick ไม่มีโค๊ดส่วนไหนที่ไปกระทบกับตัว Controller หลักที่อยู่ข้างนอกเลยครับ  (จริงๆ แล้วมันกระทบครับ กระทบครั้งเดียวตอนโหลดครั้งแรก ซึ่งไม่มีผลอยู่แล้ว)</p>
<p>หลังจากนั้นผมก็ลองเช็คไปเรื่อยๆ ก็ไม่เจออะไรที่น่าสนใจเลยครับ จนเกือบจะถอดใจแล้ว..  แต่เปลี่ยนใจลองกลับไปไล่อ่าน Wick ใหม่.. คราวนี้ผมมาหยุดตรงบรรทัดที่มีการสร้าง controller ครับ ประมาณ $controller = new $class(); อะไรประมาณนี้. และก็อย่างที่คาดการครับ บรรทัดนี้คือตัวปัญหาจริงๆ  ก็เลยต้องไล่ต่อเข้าไปข้างในครับ ว่าทำอะไรบ้าง และสุดท้ายก็เจอจนได้ครับ</p></blockquote>
<h3>สาเหตุ</h3>
<blockquote><p>เนื่องจาก CodeIgniter ถูกออกแบบมาสำหรับการใช้งานเพียง 1 Controller ต่อการเรียกครั้งนึงครับ. โดยเอาทุกอย่างมาเชื่อมเข้ากับ Controller ตามหลักของ Singleton ครับ ประเด็นคือใน code ของ Base4 และ Base5 จะทำการนำเอา Controller ที่สืบทอดมาจากมันทับเข้าไปที่ตัว Object กลางเลยครับ ซึ่งตรงนี้เลยเกิดปัญหาครับ เพราะว่า Controller ที่ถูกเรียกจาก Wick จะมีเพียง Core Library ที่เกิดจากขั้นตอนการ initialize เท่านั้นครับ  แล้วก็ถูกจับไปวางทับ Object กลางซึ่งมีการโหลด Model หรือ Non-core Library เอาไว้. Model กับ Non-core Library เลยหายไปครับ</p></blockquote>
<h3>วิธีแก้ไข</h3>
<blockquote><p>ผมใช้แนวคิดเดียวกับของ Wick ครับ  นั้นก็คือการ merge! ครับ  ผมเข้าไปแก้ไขใน Base4 และ Base5 โดยให้ทำการ merge Controller เข้ากับ Object กลางครับ แทนที่จะไปวางทับเอาดื้อๆ. การ merge ตรงนี้ผมไม่แน่ใจว่าจะส่งผลกระทบอย่างไร ต่อการทำงานในระบบใหญ่บ้าง เพราะไม่แน่ใจว่า จะมีกรณีที่บาง Module ใช้ชื่อ Properties เดียวกันหรือไม่ และอาจทำให้เกิดปัญหาได้ แต่จาการคาดคะเนโอกาสที่จะเกิดปัญหานั้นมันก็น้อยครับ. แต่ถึงอย่างนั้นก็ตาม ถ้าหลีกเลี่ยงเรื่องการใช้ชื่อซ้ำซ้อนก็จะดีครับ.</p></blockquote>
<p><em>/system/codeigniter/Base4.php</em></p>
<pre>if (class_exists( config_item('subclass_prefix')."Loader" ))
{
    eval('
    class CI_Base extends '.config_item('subclass_prefix')."Loader".' {
        function CI_Base()
        {
<strong><span style="color: #0000ff;">            $CI =&amp; get_instance();
            if (is_object($CI)) {
                foreach (array_keys(get_object_vars($CI)) as $attribute) {
                    $this-&gt;$attribute = &amp;$CI-&gt;$attribute;
                }
            }</span></strong>

            // This allows syntax like $this-&gt;load-&gt;foo() to work
            parent::'.config_item('subclass_prefix')."Loader".'();
            $this-&gt;load =&amp; $this;

            // This allows resources used within controller constructors to work
            global $OBJ;
            $OBJ = $this-&gt;load; // Do NOT use a reference.
        }
    }
    ');
}
else
{
    class CI_Base extends CI_Loader {
        function CI_Base()
        {
<strong><span style="color: #0000ff;">            $CI =&amp; get_instance();
            if (is_object($CI)) {
                foreach (array_keys(get_object_vars($CI)) as $attribute) {
                    $this-&gt;$attribute = &amp;$CI-&gt;$attribute;
                }
            }</span></strong>

            // This allows syntax like $this-&gt;load-&gt;foo() to work
            parent::CI_Loader();
            $this-&gt;load =&amp; $this;

            // This allows resources used within controller constructors to work
            global $OBJ;
            $OBJ = $this-&gt;load; // Do NOT use a reference.
        }
    }
}</pre>
<p><em>/system/codeigniter/Base5.php</em></p>
<pre>class CI_Base {

    private static $instance;

    public function CI_Base()
    {
<strong><span style="color: #0000ff;">        if (isset(self::$instance)) {
            foreach (array_keys(get_object_vars(self::$instance)) as $attribute) {
                $this-&gt;$attribute = &amp;self::$instance-&gt;$attribute;
            }
        }</span></strong>
        self::$instance =&amp; $this;
    }

    public static function &amp;get_instance()
    {
        return self::$instance;
    }
}</pre>
<p>หมายเหตุ: ไฟล์ Base4.php ผมใส่สีเฉพาะความแตกต่างจากการแก้ไขเดิมนะครับ ตามลิงค์นี้ (<a href="http://journal.kentreez.com/2008/07/22/codeigniter-my_loader-in-php4/" target="_blank">http://journal.kentreez.com/2008/07/22/codeigniter-my_loader-in-php4/</a>)</p>
<p>พอแก้ไขบั๊กจุดนี้ได้แล้ว Framework Bug Free ก็ใกล้ความจริงเข้ามาแล้วครับ</p>
]]></content:encoded>
			<wfw:commentRss>http://kentreez.com/blog/php/wick-08-bug-with-model-non-core-library/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Wick 0.8 have to edit Router.php</title>
		<link>http://kentreez.com/blog/php/wick-08-have-to-edit-routerphp/</link>
		<comments>http://kentreez.com/blog/php/wick-08-have-to-edit-routerphp/#comments</comments>
		<pubDate>Wed, 23 Jul 2008 05:57:22 +0000</pubDate>
		<dc:creator>kentreez</dc:creator>
				<category><![CDATA[CodeIgniter]]></category>
		<category><![CDATA[Notice]]></category>
		<category><![CDATA[PHP]]></category>

		<guid isPermaLink="false">http://journal.kentreez.com/?p=44</guid>
		<description><![CDATA[Ref: http://codeigniter.com/forums/viewthread/80279/P10/ ถ้าจะใช้ Library Wick ต้องเข้าไปแก้ไข /system/application/libraries/Router.php ดังนี้ครับ ... function _validate_request ($segment) { // {{{ Matchbox $this-&#62;_called = 0; // &#60;-- Inster this line (at line 239) foreach ($this-&#62;_matchbox-&#62;directory_array() as $directory) { ...]]></description>
			<content:encoded><![CDATA[<p>Ref: <a href="http://codeigniter.com/forums/viewthread/80279/P10/">http://codeigniter.com/forums/viewthread/80279/P10/</a></p>
<p>ถ้าจะใช้ Library Wick ต้องเข้าไปแก้ไข</p>
<address> /system/application/libraries/Router.php</address>
<p>ดังนี้ครับ</p>
<pre>...
function _validate_request ($segment)
{
    // {{{ Matchbox
    <span style="color: #0000ff;">$this-&gt;_called = 0; // &lt;-- Inster this line (at line 239)</span>
    foreach ($this-&gt;_matchbox-&gt;directory_array() as $directory) {
...</pre>
]]></content:encoded>
			<wfw:commentRss>http://kentreez.com/blog/php/wick-08-have-to-edit-routerphp/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Wick 0.8 in PHP4</title>
		<link>http://kentreez.com/blog/php/wick-08-in-php4/</link>
		<comments>http://kentreez.com/blog/php/wick-08-in-php4/#comments</comments>
		<pubDate>Wed, 23 Jul 2008 05:53:13 +0000</pubDate>
		<dc:creator>kentreez</dc:creator>
				<category><![CDATA[CodeIgniter]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Solutions]]></category>

		<guid isPermaLink="false">http://journal.kentreez.com/?p=42</guid>
		<description><![CDATA[Wick Ref: http://codeigniter.com/wiki/Wick/ Matchbox Ref: http://code.google.com/p/matchbox/ ผมพบว่าใน php4 จะมีการพยายามโหลดคลาส Wick สองครั้งครับ (ผมตั้ง config ให้ autoload libraries Wick) จริงๆ แล้ว Zacharias Knudsen เค้าบอกว่า Wick มัน php4 compatible นะครับ. ทำให้ผมไม่แน่ใจว่าที่ผมเจอ Error Redeclare นี่เพราะผมแก้ Framework ไปหลายจุดหรือป่าว? แต่ไม่มีปัญหาครับ Error Redeclare เรื่องเล็กนิดเดียวครับ ก็แค่ดัก If เข้าไปนิดหน่อยก็เรียบร้อย แต่ไม่รู้ว่าจะมีผลต่อ Performance หรือป่าว และ Reliable ?. ในส่วนของ Performance ก็ไม่รู้จะทดสอบอย่างไรเหมือนกัน แต่ผมได้ทำการทดลองใช้งาน $this-&#62;load-&#62;uri ทั้งใน App และใน Module [...]]]></description>
			<content:encoded><![CDATA[<p>Wick Ref: <a href="http://codeigniter.com/wiki/Wick/">http://codeigniter.com/wiki/Wick/</a><br />
Matchbox Ref: <a href="http://code.google.com/p/matchbox/"><span style="color: #9e005d;">http://code.google.com/p/matchbox/</span></a></p>
<p>ผมพบว่าใน php4 จะมีการพยายามโหลดคลาส Wick สองครั้งครับ<br />
(ผมตั้ง config ให้ autoload libraries Wick)</p>
<p>จริงๆ แล้ว Zacharias Knudsen เค้าบอกว่า Wick มัน php4 compatible นะครับ. ทำให้ผมไม่แน่ใจว่าที่ผมเจอ Error Redeclare นี่เพราะผมแก้ Framework ไปหลายจุดหรือป่าว?</p>
<p>แต่ไม่มีปัญหาครับ Error Redeclare เรื่องเล็กนิดเดียวครับ ก็แค่ดัก If เข้าไปนิดหน่อยก็เรียบร้อย แต่ไม่รู้ว่าจะมีผลต่อ Performance หรือป่าว และ Reliable ?. ในส่วนของ Performance ก็ไม่รู้จะทดสอบอย่างไรเหมือนกัน แต่ผมได้ทำการทดลองใช้งาน $this-&gt;load-&gt;uri ทั้งใน App และใน Module ซึ่งยังสามารถทำงานได้ปรกติ ก็ถือว่าโอเคครับ (มั้งนะ)</p>
<p>ถ้ามีเวลาเหลือ ผมคงจะหาวิธีแก้ที่สาเหตุ มันจริงๆ อีกทีครับ <img src='http://kentreez.com/blog/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p>แก้ไขแบบง่ายๆ ครับ  (เติมโค๊ด ๓ ตำแหน่ง)</p>
<p>จุดแรก</p>
<pre><span style="color: #0000ff;">
<pre class="brush: php; title: ; notranslate">if (class_exists('Wick')===FALSE) { // &lt;-- Insert this line (at line 36)</pre>
<p></span></pre>
<p>จุดที่สอง</p>
<pre class="brush: php; title: ; notranslate">function Wick ()
{
    &lt;span style=&quot;color: #0000ff;&quot;&gt;static $php4_run_once; // &lt;-- Insert this line&lt;/span&gt;
    &lt;span style=&quot;color: #0000ff;&quot;&gt;if (isset($php4_run_once)) // &lt;-- Insert this line
        return; // &lt;-- Insert this line
    else // &lt;-- Insert this line
        $php4_run_once = true; // &lt;-- Insert this line&lt;/span&gt;
    $ci = &amp;get_instance();</pre>
<p>จุดที่สาม</p>
<pre><span style="color: #0000ff;">
<pre class="brush: php; title: ; notranslate">} // &lt;-- Insert this line&lt;/span&gt;
/* End of file Wick.php */
/* Location: ./system/application/libraries/Wick.php */</pre>
]]></content:encoded>
			<wfw:commentRss>http://kentreez.com/blog/php/wick-08-in-php4/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>รักสามเศร้า (BASE)Loader, (APP)Loader และ MY_Loader</title>
		<link>http://kentreez.com/blog/php/%e0%b8%a3%e0%b8%b1%e0%b8%81%e0%b8%aa%e0%b8%b2%e0%b8%a1%e0%b9%80%e0%b8%a8%e0%b8%a3%e0%b9%89%e0%b8%b2-baseloader-apploader-%e0%b9%81%e0%b8%a5%e0%b8%b0-my_loader/</link>
		<comments>http://kentreez.com/blog/php/%e0%b8%a3%e0%b8%b1%e0%b8%81%e0%b8%aa%e0%b8%b2%e0%b8%a1%e0%b9%80%e0%b8%a8%e0%b8%a3%e0%b9%89%e0%b8%b2-baseloader-apploader-%e0%b9%81%e0%b8%a5%e0%b8%b0-my_loader/#comments</comments>
		<pubDate>Wed, 23 Jul 2008 05:37:38 +0000</pubDate>
		<dc:creator>kentreez</dc:creator>
				<category><![CDATA[CodeIgniter]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Solutions]]></category>

		<guid isPermaLink="false">http://journal.kentreez.com/?p=40</guid>
		<description><![CDATA[รักสามเศร้าในไฟล์ /system/codeigniter/Common.php ในฟังก์ชัน load_class ตรงส่วนที่เป็นการตัดสินใจว่าจะดึง library จากใน BASEPATH หรือ APPPATH มีโค๊ดตามนี้ if (file_exists(APPPATH.'libraries/'.config_item('subclass_prefix').$class.EXT)) {     require(BASEPATH.'libraries/'.$class.EXT);     require(APPPATH.'libraries/'.config_item('subclass_prefix').$class.EXT);     $is_subclass = TRUE; } else {     if (file_exists(APPPATH.'libraries/'.$class.EXT))     {         require(APPPATH.'libraries/'.$class.EXT);         $is_subclass = FALSE;     }     else     {         require(BASEPATH.'libraries/'.$class.EXT);         $is_subclass = FALSE;     } } จะเห็นว่าถ้ามี MY_Loader.php อยู่ใน /system/application/libraries/ [...]]]></description>
			<content:encoded><![CDATA[<p>รักสามเศร้าในไฟล์ <em>/system/codeigniter/Common.php</em></p>
<p>ในฟังก์ชัน load_class ตรงส่วนที่เป็นการตัดสินใจว่าจะดึง library จากใน BASEPATH หรือ APPPATH มีโค๊ดตามนี้</p>
<pre>if (file_exists(APPPATH.'libraries/'.config_item('subclass_prefix').$class.EXT))
{
    require(BASEPATH.'libraries/'.$class.EXT);
    require(APPPATH.'libraries/'.config_item('subclass_prefix').$class.EXT);
    $is_subclass = TRUE;
}
else
{
    if (file_exists(APPPATH.'libraries/'.$class.EXT))
    {
        require(APPPATH.'libraries/'.$class.EXT);
        $is_subclass = FALSE;
    }
    else
    {
        require(BASEPATH.'libraries/'.$class.EXT);
        $is_subclass = FALSE;
    }
}</pre>
<p>จะเห็นว่าถ้ามี MY_Loader.php อยู่ใน <em>/system/application/libraries/</em> ก็จะเข้าที่เงื่อนไขแรกเลย. ซึ่งมันจะโหลด Loader.php ซึ่งอยู่ใน <em>/system/libraries/</em> โดยไม่สนว่าจะมี Loader.php อยู่ใน <em>/system/application/libraries/</em> หรือไม่ ทั้งๆ ที่จริงๆ แล้วควรให้ความสำคัญกับ Loader ที่อยู่ใน APPPATH ก่อน BASEPATH. ตรงนี้ผมก็ไม่แน่ใจเหมือนกันว่าจุดประสงค์ที่แท้จริงของเงื่อนไขนี้คืออะไร แต่มันไม่ตรงกับความต้องการของผม ก็เลยต้องจัดการปรับเปลี่ยนเล็กน้อย เป็นแบบนี้แทนครับ</p>
<pre>if (file_exists(APPPATH.'libraries/'.config_item('subclass_prefix').$class.EXT))
{
    <span style="color: #0000ff;">if (file_exists(APPPATH.'libraries/'.$class.EXT))
        require(APPPATH.'libraries/'.$class.EXT);
    else
        require(BASEPATH.'libraries/'.$class.EXT);
    </span><span style="color: #000000;"><span style="text-decoration: line-through;"><span style="color: #ff0000;">require(BASEPATH.'libraries/'.$class.EXT);</span></span>
</span><span style="color: #0000ff;">    </span>require(APPPATH.'libraries/'.config_item('subclass_prefix').$class.EXT);
    $is_subclass = TRUE;
}
else
{
    if (file_exists(APPPATH.'libraries/'.$class.EXT))
    {
        require(APPPATH.'libraries/'.$class.EXT);
        $is_subclass = FALSE;
    }
    else
    {
        require(BASEPATH.'libraries/'.$class.EXT);
        $is_subclass = FALSE;
    }
}</pre>
]]></content:encoded>
			<wfw:commentRss>http://kentreez.com/blog/php/%e0%b8%a3%e0%b8%b1%e0%b8%81%e0%b8%aa%e0%b8%b2%e0%b8%a1%e0%b9%80%e0%b8%a8%e0%b8%a3%e0%b9%89%e0%b8%b2-baseloader-apploader-%e0%b9%81%e0%b8%a5%e0%b8%b0-my_loader/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Matchbox 0.9.4 URI</title>
		<link>http://kentreez.com/blog/php/matchbox-094-uri/</link>
		<comments>http://kentreez.com/blog/php/matchbox-094-uri/#comments</comments>
		<pubDate>Tue, 22 Jul 2008 07:08:27 +0000</pubDate>
		<dc:creator>kentreez</dc:creator>
				<category><![CDATA[CodeIgniter]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Rules & Conditions]]></category>

		<guid isPermaLink="false">http://journal.kentreez.com/?p=31</guid>
		<description><![CDATA[Matchbox Ref: http://code.google.com/p/matchbox/ ผมตั้งชื่อ Module กับชื่อ Controller ใน Module เป็นชื่อเดียวกันครับ ก็เลยเกิดข้อผิดพลาดในการ parse route ตอนแรกก็เข้าใจว่าเป็น Bug ของ Matchbox ครับ. แต่จริงๆ แล้วไม่ใช่ครับ เป็นความจงใจของ Zacharias Knudsen เค้าครับ มีกฎดังนี้ครับ www.example.com/module/controller/method/parameter The first segment represents the module in which the controller can be found. The second segment represents the controller that should be invoked. The third segment represents the method [...]]]></description>
			<content:encoded><![CDATA[<p>Matchbox Ref: <a href="http://code.google.com/p/matchbox/">http://code.google.com/p/matchbox/</a></p>
<p>ผมตั้งชื่อ Module กับชื่อ Controller ใน Module เป็นชื่อเดียวกันครับ  ก็เลยเกิดข้อผิดพลาดในการ parse route ตอนแรกก็เข้าใจว่าเป็น Bug ของ Matchbox ครับ. แต่จริงๆ แล้วไม่ใช่ครับ เป็นความจงใจของ Zacharias Knudsen เค้าครับ</p>
<p>มีกฎดังนี้ครับ<br />
<code>www.example.com/module/controller/method/parameter</code></p>
<ol>
<li>The first segment represents the module in which the controller can be found.</li>
<li>The second segment represents the controller that should be invoked.</li>
<li>The third segment represents the method that should be called.</li>
<li>The fourth, and any additional segments, represents the variables that will be passed to the controller.</li>
</ol>
<p>และมีเงื่อนไขดังนี้</p>
<ol>
<li>If the controller is located in a subfolder then the subfolder must be added as another segment between the module and controller segments.<br />
(ถ้า controller อยู่ใน subfolder ให้ใส่ subfolder ไปใน URI ด้วย ตรงระหว่าง module กับ controller อันนี้ค่อนข้าง make sence ครับ ไม่มีอะไรมาก)</li>
<li>If the controller have the same name as the module, the controller segment can be omitted.<br />
(<strong>ถ้า controller ชื่อเดียวกับ module ให้ละชื่อ controller</strong> ใน URI ครับ ก็จะกลายเปน www.example.com/module/method/parameter)</li>
<li>If the controller is in a subfolder and have the same name as the subfolder, the controller segment can be omitted.<br />
(<strong>ถ้า controller ชื่อเดียวกับ subfolder ให้ละชื่อ controller</strong> ใน URI )</li>
</ol>
<p>แล้วถ้า module, subfolder และ controller ชื่อเดียวกันหมดละ!?</p>
<p>อันนี้ผมทำการทดลองให้แล้วครับ ก็คือให้ละชื่อ controller เช่นเดิมครับ โดยจะต้องระบุ module และ subfolder ไว้ใน URI</p>
]]></content:encoded>
			<wfw:commentRss>http://kentreez.com/blog/php/matchbox-094-uri/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Codeigniter MY_Loader in PHP4</title>
		<link>http://kentreez.com/blog/php/codeigniter-my_loader-in-php4/</link>
		<comments>http://kentreez.com/blog/php/codeigniter-my_loader-in-php4/#comments</comments>
		<pubDate>Tue, 22 Jul 2008 05:05:36 +0000</pubDate>
		<dc:creator>kentreez</dc:creator>
				<category><![CDATA[CodeIgniter]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Solutions]]></category>

		<guid isPermaLink="false">http://journal.kentreez.com/?p=24</guid>
		<description><![CDATA[ใน /system/codeigniter/CodeIgniter.php จะมีทางแยกระหว่าง php4 กับ php5 อยู่ ซึ่ง php4 จะโหลดคลาส Loader ขึ้นมาก่อนและโหลดคลาส CI_Base (ใน /system/codeigniter/Base4.php) ซึ่งจะสืบทอด (extends) จาก CI_Loader ตรงนี้จึงเป็นจุดบอดเวลาที่เราต้องการจะเขียนคลาส MY_Loader เพื่อใช้งาน เพราะ Base4 มันเขียนไว้ว่ายังไงก็จะสืบถอดจาก CI_Loader ให้ได้ซะอย่างงั้น ผมพยายามหาทางออก ที่จะไม่ต้องแก้ไขตัว Core ของ CodeIgniter แต่ก็จนปัญหาครับ. จริงๆ แล้วมันมีอยู่อีกแบบนึงคือ เขียน CI_Loader ขึ้นมาใหม่เองทั้งหมด (แบบที่ Matchbox ทำ) แล้ววางไว้ที่ /system/application/libraries/Loader.php แต่ก็ดูจะผิดจุดประสงค์ไปหน่อยครับ เพราะว่า MY_Loader ของผมต้องการจะต่อเติม หรือแก้ไขเฉพาะบาง method ที่อยู่ใน CI_Loaderเท่านั้น. สุดท้ายก็ต้องตัดสินใจแก้ที่ Core ของมันครับ ที่จะแก้คือไฟล์ /system/codeigniter/Base4.php [...]]]></description>
			<content:encoded><![CDATA[<p>ใน <em>/system/codeigniter/CodeIgniter.php</em> จะมีทางแยกระหว่าง php4 กับ php5 อยู่ ซึ่ง php4 จะโหลดคลาส Loader ขึ้นมาก่อนและโหลดคลาส CI_Base (ใน <em>/system/codeigniter/Base4.php</em>) ซึ่งจะสืบทอด (extends) จาก CI_Loader ตรงนี้จึงเป็นจุดบอดเวลาที่เราต้องการจะเขียนคลาส MY_Loader เพื่อใช้งาน เพราะ Base4 มันเขียนไว้ว่ายังไงก็จะสืบถอดจาก CI_Loader ให้ได้ซะอย่างงั้น</p>
<p>ผมพยายามหาทางออก ที่จะไม่ต้องแก้ไขตัว Core ของ CodeIgniter แต่ก็จนปัญหาครับ. จริงๆ แล้วมันมีอยู่อีกแบบนึงคือ เขียน CI_Loader ขึ้นมาใหม่เองทั้งหมด (แบบที่ Matchbox ทำ) แล้ววางไว้ที่ <em>/system/application/libraries/Loader.php</em> แต่ก็ดูจะผิดจุดประสงค์ไปหน่อยครับ เพราะว่า MY_Loader ของผมต้องการจะต่อเติม หรือแก้ไขเฉพาะบาง method ที่อยู่ใน CI_Loaderเท่านั้น.</p>
<p>สุดท้ายก็ต้องตัดสินใจแก้ที่ Core ของมันครับ ที่จะแก้คือไฟล์ <strong><em>/system/codeigniter/Base4.php</em></strong> ครับ</p>
<p>จากเดิม</p>
<pre>class CI_Base extends CI_Loader {
    function CI_Base()
    {
        // This allows syntax like $this-&gt;load-&gt;foo() to work
        parent::CI_Loader();
        $this-&gt;load =&amp; $this; // This allows resources used within controller constructors to work
        global $OBJ;
        $OBJ = $this-&gt;load; // Do NOT use a reference.
    }
}</pre>
<p>เปลี่ยนเป็น</p>
<pre><span style="color: #0000ff;">if (class_exists( config_item('subclass_prefix')."Loader" ))
{
    eval('
    class CI_Base extends '.config_item('subclass_prefix')."Loader".' {
        function CI_Base()
        {
            // This allows syntax like $this-&gt;load-&gt;foo() to work
            parent::'.config_item('subclass_prefix')."Loader".'();
            $this-&gt;load =&amp; $this; // This allows resources used within controller constructors to work
            global $OBJ;
            $OBJ = $this-&gt;load; // Do NOT use a reference.
        }
    }
    ');
}
else
{</span>
    class CI_Base extends CI_Loader {
        function CI_Base()
        {
            // This allows syntax like $this-&gt;load-&gt;foo() to work
            parent::CI_Loader();
            $this-&gt;load =&amp; $this; // This allows resources used within controller constructors to work
            global $OBJ;
            $OBJ = $this-&gt;load; // Do NOT use a reference.
        }
    }
<span style="color: #0000ff;">}</span></pre>
<p>แค่นี้ก็จะสามารถใช้งาน MY_Loader ได้แล้วล่ะครับ</p>
]]></content:encoded>
			<wfw:commentRss>http://kentreez.com/blog/php/codeigniter-my_loader-in-php4/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

