Well... I'm out of ideas on what to write about. Do you have any ideas? Please, write me in any comment section you find, and I will do my best to tell you about that particular subject

Step 1.2: Again about MVC and CodeIgniter – The views

Created at: January 21, 2015; Last update: January 21, 2015

(created: January 21, 2015; last update: -)

In the previous tutorial we worked a bit with the controllers. Now, remember how I told you that when talking about MVC patterns, the controllers send the data to the views so that the data would be outputted to the browser?

Well, now we will talk a bit about these views. In particular, we will talk about the view that is called by the Welcome controller, “welcome_message“.

The views can be found in application/views directory, so we will find the welcome_message.php in there.

We will see a plain page if we look inside it… so, let’s delete everything and just create a basic html structure:

application/views/welcome_message.php

XHTML

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

<!DOCTYPE html>

<html>

<head>

<meta http-equiv="Content-Type"content="text/html; charset=UTF-8" />

<title>Your Website</title>

</head>

<body>

<h1>Hello from your CodeIgniter application</h1>

<p>Hello</p>

</body>

</html>

Now, if in the controller we’ve defined some variables (and we did), how would we go about using them in the view? As I already mentioned in the previous tutorial, when loaded from the controller, the view can receive variables inside an array:

PHP

1

$this->load->view('welcome_message',$data);

Inside the view, the variables can be accessed by calling the keys of the array as variables. So, if for example we have an array like this one:

PHP

1

$data=array('page_title'=>'This is the title of the page','another_var'=>6);

…when we will be inside the view we can access those keys by simply translating them into variables:

PHP

1

2

echo$page_title;

echo$another_var;

Let’s put what we’ve learned into practice. As you remember, in the controller we’ve defined a page title ($data[‘page_title’] = ‘Our first CodeIgniter application’; ). Now in the view we simply replace the hard-coded page title with the variables sent by the controller:

C++ is a very strong language and sometimes it drives me nuts 😉 So don’t be jealous LOL
IMHO, .Net has a limitation of being too heavy. Overly heavy in fact and hosting server must be IIS (yay?). All the components are tightly coupled and their associated costs can be problem, not to mention these components are never known to be resource friendly. Costs and maintenance is a major issue with .Net. Then there’s a problem where you’re locked down with a one framework only.

PHP’s components on the other hand are very loosely coupled. From servers down to associated framework are all loosely coupled. I have the option to choose what framework i use for which project and switching from one framework to another doesn’t carry a steep learning curve – once you get the concept and language right.

Till this page u where on my adblock list,
but from this page on u are white listed on all blocking+popup extension,
i have to say that , yout tutorial is awesome piece of an art , i would recommend all beginner in codeigniter to learn from this tutorials ,
writer, keep doing , awesome work man, thanks again, i will keep visit ur site, 🙂