MVC is the architectural pattern. That is used to separate an application into three main component: The model, the view, the controller.
The Model: Model objects are the parts of application that implement the logic for the application's data domain. Often model objects retrieve and store model state in a database.For example, a Product object can retrieve information from database, operate on it, and then update information back to product table in SQL server.
The View: Views are the components that display the application's user interface(ui). Typically,UI is created from the model data.
The Controller: Controllers are the components that handle user interaction. working with model and ultimately,select a view to reder.That display UI. In an MVC application, View only display information for end user.Controller handle and response to user input and interaction.
To write a function, code the function keyword followed by name of the function, followed by a set of parentheses.
within the parentheses of a function, you can code an optional paramater list that contain on or more parameters.
To code a function that returns data, code the return statement in the body of function. The return statement ends the execution of the function and return the specified value.
When you call a fucntion, the argument in the argument list must be in the same order as the parameters in the parameter list defined by the function, and they must have compatible data types.
Example: function avf_of_3($x,$y,$z){ return ($x+$y+$z)/3; }
How to pass arguments by value and by reference in PHP
By default, all argument are passed by value to the function that are called. This means that PHP send a copy of argument(the value of original variable) to the function, not the argument itself. As the result, the function can't change the value of orginal argument.
To allow a function to modify the original argument insted of a copy, You can can code an ampersand(&) in font of the parameter. In that case, The argument is passed by reference. This mean that a reference to the original argument is sent to the function. Then, when the function changes the parameter, it actually changing the original argument.
When an HTML <form> tags uses the GET method to pass data to a php page, the values is stored in a $_GET array. Beacause this array is a part of PHP, it is called build-in array.
Beacause this array uses the GET method, these values is passed as a part of the URL that request the pages.
For example: detail.php?firstname=tien&lastname=dung.
To retrieve values form $_GET array, you code as following:
For example: $firstName=$_GET['firstname'].
How to use the build-in $_POST array.
When an HTML <form> tags uses the POST method to pass data to a php page. so passed data will be stored in $_POST array.
The $_POST array works like $_GET array.
So when should use the GET method and when should use the POST method.
Using GET method:
when request is for a page that gets data from a database server.
when request can be excuted multiple times without causing any problem.
Using POST method :
when the request that write data to a database server.
When excuteing the request multiple times that may cause problems.
When you don't want to include the parameters in URL.
PHP provides for six data types. Each data type is used to store a different type of data.
An integer is a whole number that can start with positive or nagative sign.
A double value consists of a positive and nagative sign,digits, an optional decimal point, and optional decimal digist.
A boolean data type is used to represent a boolean value that is either True or False.
A string data type contains string that are made up of any characters.
An array data type is used to store one or more items called elements.Each element stores a value that you can refer to with an index.
An object data type.
Declaring variables in PHP.
Variable stores a value that can change as the program executes. In php, variables are easy to spot beacause they all begin with dollar sign ($).
To declare a variable, code the dollar sign ($) followed by the variable name. Then, to assign a value to the variable, code assignment operator (=) followed by an expression that return value for the variable.
Example: $count=10; or name='nguyen tien dung'.
Declaring constants in PHP.
Constants like variable except that once they are declared they can't change or undefined.