Simple File รวมปัญหาใน Zend หรือไม่

ฉันได้สร้างโปรเจ็กต์ zend บน Ubuntu ซึ่งอยู่ในไดเร็กทอรี /var/www/student/

ตอนนี้ฉันมีไฟล์ head.phtml ในตำแหน่งนี้:

/student/application/views/scripts/index/head.phtml

เมื่อฉันพยายามรวมไฟล์ head.phtml เข้าไป

/student/application/modules/test/views/scripts/all/index.phtml

แบบนี้:

echo $this->partial('index/head.phtml');

มันทำให้ฉันมีข้อผิดพลาดดังต่อไปนี้:

Message: script 'index/head.phtml' not found in path (/var/www/student/application/modules/notification/views/scripts/) 

การรวมไฟล์เป็นงานที่ยากสำหรับฉันเสมอ วิธีแก้ไขปัญหานี้ ฉันต้องรวมไฟล์นี้ในหลาย ๆ โมดูล แล้วอะไรคือวิธีแก้ปัญหาแบบถาวรสำหรับสิ่งนี้ ซึ่งฉันไม่ควรเดาเส้นทาง

ขอบคุณ


person Student    schedule 29.05.2011    source แหล่งที่มา
comment
ลอง echo $this->partial('all/head.phtml');   -  person Karl Laurentius Roos    schedule 29.05.2011


คำตอบ (2)


คุณสามารถเพิ่มหลายเส้นทางเพื่อค้นหาไฟล์มุมมองสคริปต์ วิธีที่ดีที่สุดคือทำในไฟล์บูตสแตรปสำหรับไฟล์ทั่วไปทั้งหมดของคุณ (เช่น head, footer, metas...)

เพียงเพิ่มเมธอด setupView ใน bootstrap ของคุณที่คุณจัดการกับทุกสิ่งที่เป็นจริงตามมุมมองของคุณ:

protected function _initView()
{
    $view = new Zend_View();

    // setup your view with jquery and other stuffs... 
    // [ ... ]

    // add the view directory to the stack of scripts paths
    $view->addScriptPath(APPLICATION_PATH . '/views/scripts/');
}
person Jean-Christophe Meillaud    schedule 30.05.2011
comment
คริสตอฟ เมลลา: ถูกต้องเลย addScriptPath() คือคำตอบ ฉันโพสต์วิธีแก้ปัญหาของฉันเช่นกัน - person Student; 30.05.2011

ฉันเพิ่มบรรทัดต่อไปนี้ในฟังก์ชัน init() ของคอนโทรลเลอร์

public function init() {
    $this->view->addScriptPath( APPLICATION_PATH . '/views/scripts/' );
}

เพิ่มไฟล์ head.phtml ในมุมมองดังนี้:

echo $this->partial('index/head.phtml');

เพิ่มไฟล์เรียบร้อยแล้ว

person Student    schedule 30.05.2011