Hosted by Dailymotion. For legal issues report at the Copyright Center, report us on DMC, or use the Instant Removal tool.
Lynda. Up and Running with PHP CodeIgniter / Section 2 - 5. Generating output with a view
1 Views • Aug 22, 2014
Description
A view is a partial or complete webpage. Designers like views because it's most HTML with a very bar minimum in PHP code, and what logic is there are four hs and so forth. Views can be embedded in other views, which allows for hierarchies and cleaner, more reusable code. Even though they're webpages, a view cannot be called directly. It can be only loaded by controller. So with this context, let's get that HTML out of the controller and into a view.
From NetBeans, I'm going to navigate to the Views directory. Right now, there's only two files. The same placeholder index.html and welcome message.php. Open welcome message.php to see what's inside. Scrolling through, it's a complete html five page with no php whatsoever. At the bottom there is one little anomaly. Page rendered in elapsed time in curly braces. This is a pseudo variable from the benchmarking class... I'll get into class libraries in a later chapter.
For the time being, just close welcome message. Then create a new file in views called magazines, plural, .php. And the magazine controller. Let's copy that HTML. And paste it into magazines.php. Next, we'll need to load the view. Take a look at the welcome controller for just a second, and see how it loads the view using this. What is this? This has a special meaning in CodeIgniter. It's a singleton CodeIgniter instance, which means there can only be one copy of it throughout the entire application, which prevents duplicates in overhead. When various functionality is loaded, it's attached to the instance, in such a way, that it can be referenced, like a property of the instance. I'll demonstate how this works in just a moment.
Close the Welcome controller and go back to the Magazine controller. We'll replace the echo with this, load and we're going to load a view. Named magazines. Followed by semicolon and save. I'm going to go back to the browser and refresh. Make sure that nothing has changed. It says, My magazines, again. Now there's no limit to the number of views that are loaded. If you chain them, they'll be appended. Let's experiment a little bit by going back to the magazine controller. And copying and pasting this load view.
And doing it twice. Save, then in the browser, refresh. Now there's two My magazines. If I view the page source. I can see that the only markup that is shown is what was in my view. See what I mean by coding neither having low overhead. None of the (UNKNOWN) fully formatted HTML documents. Wait a second. That's actually something I want. I'm going to get into more detail about how to set up a proper template in an outcoming chapter. Close the source, and go back to NetBeans. Let's clean up the controller by removing that extra line, and then save.
In this chapter, I've defined what CodeIgniter is, and gave a number of reasons why it should be used. I've introduced the Model View Controller development pattern. Then I installed CodeIgniter and tested the database configuration. Starting with some code and concepts, I created a static page controller and finally generated output using a view. At this point, we're ready to display content but we don't actually have anything to show. No worries, we'll sort that in the next chapter as we model magazines in the database.
Keywords & Tags
More from User
Lynda. Up and Running with PHP CodeIgniter / Section 4 -2. Creating a form to add magazines
Mubasharamin52
Lynda. Up and Running with PHP CodeIgniter / Section 3 -4. Displaying a magazine
Mubasharamin52
Lynda. Up and Running with PHP CodeIgniter /4. Adding Functionality with Libraries Section 4 -1. What are CodeIgniter libraries
Mubasharamin52
Lynda. Up and Running with PHP CodeIgniter / Section 3 - 3. Saving magazines using active records
Mubasharamin52
Lynda. Up and Running with PHP CodeIgniter / Section 3 - 2. Modeling a magazine
Mubasharamin52
Lynda. Up and Running with PHP CodeIgniter / Section 3 - 1. What is a model and how is it used
Mubasharamin52
Related Videos
Read Web Programming for Business: PHP Object-Oriented Programming with Oracle Ebook Free
Rmetz
Programming in JAVASCRIPT - Tutorial 4 | Generating an Output
ComputerScienceVideos
Applications of PHP website development Programming Language|PHP Web Development Company | Webhonchoz
Webhonchoz Itservices
Read PHP MySQL Web Programming Interview Questions Answers and Explanations: PHP MySQL FAQ
Boesen
Just Enough Web Programming with XHTML PHP and MySQL
Jamesgoff
PHP Programming and Web Hosting Benefits
AyanaShondra594