HomePHP Returning Strings from Views with Code Igniter
Returning Strings from Views with Code Igniter
When it comes to generating both static and dynamic web pages, CodeIgniter gives PHP developers the liberty of working with different approaches that can be easily adapted to suit the requirements of a huge variety of web applications. Building web pages using CI demands that you always deal with one or multiple views, generally represented in the form of HTML files that contain embedded PHP variables. Therefore, if youíre a CI user who want to learn to manipulate views in some clever ways, keep reading. In this series of articles, youíll find a comprehensive guide to several methods you can implement within your own CI-based applications to handle view files in a truly efficient manner.
Now that you know what to expect from this article series, itís time to recapitulate briefly the topics that were discussed in the last installment. In that particular tutorial I demonstrated how to build a simple MySQL-driven application by using a combination of the ď$this->load->vars()Ē method and nested views.
This approach allowed me to generate independently different sections of a front page, whose main area was populated with data fetched from a sample ďusersĒ MySQL table. Admittedly, including views within other views is a useful method that permits you to use certain parts of a web document across multiple pages of a web site; but the most interesting aspect of it is that it can be implemented in different ways.
Speaking more specifically, itís possible to feed the ď$this->load->view()Ē method of CI a third Boolean parameter, to return the contents of a view to calling code after the view has been parsed. This is a handy variation of the method demonstrated in the previous article, and in this tutorial Iíll be taking a close look at it, so you can grasp its underlying logic.
Now, itís time to get things rolling on and see how to return strings from views with CodeIgniter. Letís do it!