Views are the V in MVC. Views are responsible for generating the specific output required for the request. Often this is in the form of HTML, XML, or JSON, but streaming files and creating PDFs that users can download are also responsibilities of the View Layer.
CakePHP comes with a few built-in View classes for handling the most common rendering scenarios:
To create XML or JSON webservices you can use the JSON and XML views.
To serve protected files, or dynamically generated files, you can use Sending files.
To create multiple themed views, you can use Themes.
View Templates
The view layer of CakePHP is how you speak to your users. Most of the time your views will be showing (X)HTML documents to browsers, but you might also need to serve AMF data to a Flash object, reply to a remote application via SOAP, or output a CSV file for a user.
By default CakePHP view files are written in plain PHP and have a default extension of .ctp (CakePHP Template). These files contain all the presentational logic needed to get the data it received from the controller in a format that is ready for the audience you’re serving to. If you’d prefer using a templating language like Twig, or Smarty, a subclass of View will bridge your templating language and CakePHP.
A view file is stored in /app/View/, in a subfolder named after the controller that uses the file. It has a filename corresponding to its action. For example, the view file for the Products controller’s “view()” action would normally be found in /app/View/Products/view.ctp.
The view layer in CakePHP can be made up of a number of different parts. Each part has different uses, and will be covered in this chapter:
views: Views are the part of the page that is unique to the action being run. They form the meat of your application’s response.
elements: smaller, reusable bits of view code. Elements are usually rendered inside views.
layouts: view files that contain presentational code that wraps many interfaces in your application. Most views are rendered inside a layout.
helpers: these classes encapsulate view logic that is needed in many places in the view layer. Among other things, helpers in CakePHP can help you build forms, build AJAX functionality, paginate model data, or serve RSS feeds.
มุมมองที่เป็น V ในการทำงาน . มุมมองที่เป็นผู้รับผิดชอบสำหรับการสร้างผลผลิตเฉพาะที่จำเป็นสำหรับการร้องขอ นี้มักจะเป็นในรูปแบบของ HTML , XML หรือ JSON , แต่สตรีมมิ่งไฟล์และสร้างไฟล์ PDF ผู้ใช้สามารถดาวน์โหลดยังมีความรับผิดชอบในมุมมองของชั้นCAF มาพร้อมกับไม่กี่ตัวในชั้นเรียนสำหรับการจัดการการแสดงผลดูสถานการณ์ที่พบบ่อยที่สุด :การสร้าง XML หรือ JSON เว็บบริการคุณสามารถใช้ JSON และความคิดเห็น XMLเพื่อใช้ป้องกันไฟล์หรือแฟ้มที่สร้างแบบไดนามิก , คุณสามารถใช้ในการส่งไฟล์เพื่อสร้างมุมมองที่หลากหลายรูปแบบ คุณสามารถใช้ชุดรูปแบบดูแม่แบบวิวชั้นของ CAF เป็นวิธีที่คุณพูดคุยกับผู้ใช้ของคุณ ส่วนใหญ่ของเวลาที่ความคิดเห็นของคุณจะถูกแสดง ( x ) เอกสาร HTML เบราว์เซอร์ แต่คุณยังอาจต้องการที่จะให้บริการข้อมูล AMF ไปยังวัตถุ Flash ตอบกลับไปยังระยะไกลโปรแกรมผ่านสบู่ หรือส่งออกไฟล์ CSV สำหรับผู้ใช้โดยไฟล์ CAF มุมมองเริ่มต้นเขียนใน PHP และต้องเริ่มต้นธรรมดานามสกุล . CTP ( แม่แบบ CAF ) ไฟล์เหล่านี้มีทั้งหมดโดยใช้ตรรกะต้องได้รับข้อมูลที่ได้รับจากการควบคุมในรูปแบบที่พร้อมสำหรับผู้ชมที่คุณกำลังให้บริการ . ถ้าคุณต้องการใช้ templating ภาษา เช่น กิ่งไม้ หรือ Smarty เป็น subclass ของวิวจะสะพานภาษา templating และ CAF .ไฟล์มุมมองที่เก็บไว้ใน / app / วิว / ในโฟลเดอร์ย่อยชื่อหลังจากที่ตัวควบคุมที่ใช้ไฟล์ มันเป็นชื่อที่สอดคล้องกับการกระทำของมัน ตัวอย่างเช่น , ไฟล์มุมมองสำหรับผลิตภัณฑ์ควบคุม " view() " กระทำ โดยปกติจะพบใน / app / วิว / ผลิตภัณฑ์ / view.ctp .มุมมองชั้นใน CAF สามารถถูกสร้างขึ้นจากจำนวนของชิ้นส่วนที่แตกต่างกัน แต่ละส่วนมีการใช้แตกต่างกัน และจะกล่าวถึงในบทนี้มุมมอง : มุมมองที่เป็นส่วนหนึ่งของหน้าที่เป็นเอกลักษณ์ของการกระทําที่ถูกเรียกใช้ พวกเขาฟอร์มเนื้อของการตอบสนองของโปรแกรม .องค์ประกอบ : ขนาดเล็กสามารถบิตของรหัสดู องค์ประกอบที่มักจะแสดงในมุมมองรูปแบบ : แฟ้มที่ประกอบด้วยโดยใช้รหัสที่ตัดมีอินเตอร์เฟสในใบสมัครของคุณ มุมมองส่วนใหญ่จะแสดงผลในรูปแบบผู้ช่วย : ชั้นเรียนเหล่านี้สรุปดูตรรกะที่จำเป็นในหลายสถานที่ในมุมมองของเลเยอร์ ในสิ่งอื่น ๆ , ผู้ช่วยใน CAF สามารถช่วยให้คุณสร้างฟอร์มสร้าง Ajax การทํางาน , ใส่เลขหน้าแบบจำลองข้อมูลหรือให้บริการ RSS ฟีด
การแปล กรุณารอสักครู่..
