 |
|
ใช้ Framework ครับ เช่น Laravel,CodeIgniter
โดยอ้างอิงรูปแบบ Relationship ตัวอย่าง Design เช่น
Database
tb_articles (ใส่ข้อมูลหลักที่ไม่ใช่ 2 ภาษา)
id,created_at,updated_at
1,11/01/11,11/02/11
tb_article_descriptions (ใส่ข้อมูลที่ต้องการให้เป็น 2 ภาษาหรือมากกว่า)
id,article_id,lang(enum=Eng,Th),name,intro,description,created_at,updated_at
1,1,Eng,Test,intro,des
2.1.Th,ทดสอบ,รายละเอียด
Model
::: Class Article
public function descriptions() // array article มีมากมายใน article description
{
return $this->hasMany('App\Models\ArticleDescription');
}
public function lang($lang) // โดยให้ article ตัวนี้หาตาม where language
{
return $this->descriptions->where('lang',$lang)->first();
}
::: Class ArticleDescription
public function aritcle() // array article descripton ตัวนี้ เป็นของ article
{
return $this->belongsTo('App\Models\Article');
}
ส่วนในหน้า .base ใช้เครื่องมือ Localization ที่มีให้ จัดการเนื้อหาที่ไม่เกี่ยวข้องกับข้อมูลใน Database และเก็บค่า Local ไว้ที่ Session เพื่ออ้างอิงกับ Relationship ใน Model คือ $lang
ปล. Algorithm นี้รองรับมากกว่า 2 ภาษา
|
ประวัติการแก้ไข 2021-01-26 09:46:54 2021-01-26 09:52:56
 |
 |
 |
 |
Date :
2021-01-26 09:45:45 |
By :
Genesis™ |
|
 |
 |
 |
 |
|
|
 |