Zend Framework Courses — MVC

Hi, in this article i will mention about the topic MVC that used in Zend Framework.

I think, most of you have heard about the term MVC. So, what is this MVC? MVC stands for Model-View-Controller and it creates the basic substructure of current modern web applications. Let’s look at the below diagram;

Model: The functional structure of applications are located here. This functional structure is always behind a abstract system. In other words, this part is where the business logic is located in.

View: The data is represented to the user in this part. In general, Controller assigns data to View and View shows data to user. You can see HTML data structure here.

Controller: Controller acts like a bridge among the whole structure. Controllers manipulates the Models and it decides on which data goes which View. I want to advice you something;

The less code you used in Controller, the better. So, minify your code in Controller!

We talked about MVC theoritically above, let’s talk about what do all stuffs above equals to in Zend world. As you remember, we have created a project previous article and the folder structure was like below;

We can say following things by looking at the folder structure. In this project there is a Controller called Index. This controller manipulates some models that exist under models(I assumedd that or models are under models folder) folder. Controller does some operations by using datas that fetched from models and assigns the output to the View. If you go to following

url;

http://zfproject/index/index

you will execute above scenario. As you can see, there is a view file under “application/views/scripts”. For example, there is a view folder called “index” for Index Controller.for each Controller . We use index controller and index action above so, index.phtml will be displayed under index folder.

There are lots of things to talk about Zend MVC but i tried to mention about basic points. I will be mention about Zend MVC in following articles partially. Please do not hesitate to ask here about this topic.

See you in next article…

Zend Framework Courses-Introduction

Hello everyone, I am here with Zend Framework tutorials.In this series, i will try to tell you about Zend Framework by using my experiences.Zend Framework will be discussed on Linux(Ubuntu).

Before starting the tutorial i want to make an important reminder.I would recommend you to practise examples at the end of each subject, the more you practise, the easier you understand.
In this tutorial, i will tell you about Zend Framework installation and i will give you an example at the end.

What is Zend Framework?
Zend Framework is a library written in PHP that contains several components. Nowadays, it is widely used on web applications.

Prerequisites:

  1. PHP 5.x
  2. Apache(Lighttpd, or any other web server software)
  3. Zend Framework

Installation:

  1. Download the latest version of Zend Framework from here.
  2. After download, copy the Zend Framework folder to somewhere you want. We will assume”/opt/” folder in this example.

<br />
/opt/Zend/<br />

We will create project by using Zend Framework CLI(Command Line Interface). In order to use CLI, there must be a command that linked to “/opt/Zen/bin/zf.sh” shell script.For this, please run below command.

<br />
ln -s /opt/home/zend/bin/zf.sh /opt/home/bin/zf<br />

You must get the version of current version of installed Zend Framework when you execute the command “zf — version”.If it is OK, it means you have successfully installed Zend Framework

Creating Project:

Inorder to create project, please execute below command in command line.

<br />
zf create project zfproject<br />

We have a new project now! This project has only the folder structure that Zend specified.In order to use Zend Framework, we must let our project know about Zend library.We have two ways for this.

  1. Copy the “Zend” folder exists under library folder in downloaded Zend Framework folder to library folder in our zfproject.After copy operation, you can use all of the Zend components
  2. Open up the “php.ini”.If you don’t know where the “php.ini” is, you can find it by executing this command in command line “php — ini”.My php.ini files are in /etc/php5/cli/ and /etc/php5/cgi/ and i will edit both of them.Find the word “include_path” in the file and update its value as “/opt/Zend/libary” .By doing this, you can use Zend library for all the projects that exist on your system.

Creating virtual host:

In order to make your project work on the browser, you must create a virtual host record for your project.I am using Lighttpd for web server application and my virtual host folder is “/etc/lighttpd/sites-enabled”.I create a file called “zfproject.conf” and make its content like below:

<br />
$HTTP[&quot;host&quot;] =~ &quot;fd&quot; {<br />
server.document-root = &quot;/home/huseyin/workspace/zfproject/public&quot;<br />
accesslog.filename = &quot;/var/logs/zfproject.access.log&quot;<br />
setenv.add-environment = (&quot;ZF_ENV&quot; =&gt; &quot;locallinux&quot;,<br />
&quot;ZF_INST&quot; =&gt; &quot;zfpoject&quot;)<br />
}<br />

An important point here is, server.document.root value must be the “public” folder of our project.

Restart the web server after virtual host creation.After that, open up “/etc/hosts” file and add the host entry next to “127.0.0.1”.You can view the project on browser by doing this.

If you can see the sample Zend Framerwork page on the browser after enter the url “zfproject”, it means that everything is OK.

That’s all for installation, If you have any question, please do not hesitate to ask here. I will be answer the questions as soon as possible.

See you on next tutorial…