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!