Tik’s Blog

ร้อยแปดพันเก้า

Posts Tagged ‘CakePHP

Cache not configured…CakePHP 1.2

without comments

ปัญหานี้อาจเกิดขึ้นได้ถ้าเราไม่ได้สร้าง cache folder ใน app/tmp (ลองใน OS X)

วิธีแก้ง่ายๆก็แค่สร้าง app/tmp/cache แล้วก็ chown/chgrp ให้ Apache เขียนลงใน folder นี้ได้

Written by sukita

กรกฎาคม 22, 2008 at 4:04 am

บันทึกโพสใน Programming

Tagged with

การระบุชื่อ class สำหรับ input div ใน CakePHP

without comments

ปกติเวลาใช้ $form->input() CakePHP จะสร้างโค๊ดประมาณนี้ให้เรา:

<div> class="input text">
    <label for="name">Name:</label>
    <input id="name" type="text" name="data['User']['name']"/>
</div>

class ชื่อ input กับ text ถูกเพิ่มให้อัตโนมัติอยู่แล้ว (คาดว่าเพื่อที่จะให้เรามี hook เพื่อใช้ cssตกแต่งหน้าตาได้ง่ายๆ)

ถ้าเราต้องการ class พิเศษสำหรับ div นี้นอกเหนือจาก input และ text ก็ง่ายๆ แค่ override โดยระบุค่าใน argument สำหรับ input ได้เลยเช่น:

$form->input('User.name', array('div' => 'input text custom-class'));

ซึ่งจะทำให้ Cake สร้างโค๊ดแบบนี้:

<div> class="input text custom-class">
    <label for="name">Name:</label>
    <input id="name" type="text" name="data['User']['name']"/>
</div>

Written by sukita

มิถุนายน 9, 2008 at 7:50 am

บันทึกโพสใน Programming

Tagged with

CakePHP regexp for unicode alphaNumeric

without comments

Don’t know if it’s the perfect one, but at least it works for Thai words.

/[pLpM]+/iu

Written by sukita

มิถุนายน 7, 2008 at 4:00 am

บันทึกโพสใน Programming

Tagged with

ใส่ text หลัง input ใน CakePHP

without comments

คุณสามารถใส่เนื้อหาต่อท้าย input() ใน CakePHP ได้โดยที่เนื้อหานั้นยังอยู่ใน div ของ label/input ที่ Cake สร้างมาให้โดยใส่ 'after' เข้าไปใน options ของ input() ครับ ยกตัวอย่างเช่น:

echo $form->input('Model.field', array('label' => 'Value:', 'after' => 'ตัวหนังสือที่ถูกแสดงหลัง input')); 

ค่าของ 'after' จะถูกต่อท้าย input

ในกรณีคล้ายๆกันคุณสามารถใช้ 'before'  ถ้าอยากแสดงเนื้อหาก่อน input box ได้ด้วย (แต่จะแสดงหลัง label นะครับ)

Written by sukita

พฤษภาคม 23, 2008 at 4:17 am

บันทึกโพสใน Programming

Tagged with

อีกหนึ่งวิธีในการแสดง password field ใน CakePHP 1.2

without comments

นอกจากการใช้ $html->password(‘User.password’) เพื่อแสดง field สำหรับ input password ยังมีอีกวิธีที่ทำได้นั่นก็คือการใช้ $html->input(‘User.password’, array(‘type’ => ‘password’, ‘label’ => ‘รหัสผ่าน:’))

วิธีที่สองต่างกับแบบแรกโดยที่มันสร้าง <div> เพื่อครอบ <label> กับ <input> ที่ generate โดย view ของ CakePHP และก็ทำงานกับ validation ได้ด้วย

แต่วิธีแรกจะสร้างเฉพาะ <input> สำหรับ password เท่านั้น โดยไม่สร้าง label ให้

Written by sukita

พฤษภาคม 15, 2008 at 5:54 pm

บันทึกโพสใน Programming

Tagged with

Fixing CakePHP Tutorial 403/404 problems in Leopard

with 2 comments

In case your newly created CakePHP site looks weird without any styling, try enabling the mod_rewrite (see “8.5 A Note on mod_rewrite“).

You might get a 403 Forbidden error when changing the AllowOverride directive to all. If you get one, open the Console and see Apache’s error log. It might be because you haven’t added FollowSymLinks option. Try adding that and the configuration should look something like:

<Directory “/Users/John/Sites/cake”>

    Options Indexes MultiViews FollowSymLinks

    AllowOverride All

    Order allow,deny

    Allow from all

</Directory>

Now, if everything works fine after that, cool. If you’re getting a 404 Not Found error saying something like:

The requested URL /Users/John/Sites/cake/app/webroot/ was not found on this server.

Chances are because you’re using Web Sharing in Leopard and your site is located in your <home>/Sites directory. If that’s so, try adding the RewriteBase directive to your .htaccess file in Cake’s root directory. The file should now look something like this:

<IfModule mod_rewrite.c>

   RewriteEngine on

   RewriteBase /~John/cake

   RewriteRule    ^$ app/webroot/    [L]

   RewriteRule    (.*) app/webroot/$1 [L]

</IfModule>

Hopefully that’ll fix the problem.

Written by sukita

เมษายน 25, 2008 at 8:49 am

บันทึกโพสใน Uncategorized

Tagged with