A simple MVC PHP CodeIgniter Example

A simple MVC PHP CodeIgniter Example

Right now, will make a straightforward example dependent on PHP CodeIgniter MVC based example.

​In our last article, we have found out about PHP CodeIgniter. Now, in this article, we will make a basic view page utilizing HTML and will open that view by utilizing a ​​controller. Along these lines, we should begin.

1) Make a view page

A simple MVC PHP CodeIgniter Example

​First, we will make a view page which will be appeared to the client. To do this open your CodeIgniter envelope (put in wamp/xampp organizer) → open applications, here you will see different envelopes, however, as we need to make a view we will open perspectives organizer.

​In this envelope, make a document named “Mypage.php” spare this record and compose the accompanying code in it.

2) Make a controller document

A simple MVC PHP CodeIgniter Example

Now, we will make a controller document to open our view page.

For this, make a document named “MyController.php” in controller folder.​ ​Write this code to the file.​​

Note: Your class name and document name must be the same.

Codeigniter PHP example

​The controller makes your work simple in CodeIgniter.​ ​Here, line 2 is a CodeIgniter syntax line you don’t have to think about this for the present simply duplicate it from CodeIgniter naturally controller named Welcome.php. Line 4 speaks to your group named “MyController” which stretches out CI_Controller to get to the strategies characterized in CI_Controller class. Line 7 has a function named record() at whatever point a solicitation will result in these present circumstances function, it will stack a view page named “MyPage“.

3) Run the File

​To run the record type this URL in your program: “http://localhost/democodeigniter/index.php/Mycontroller/” or “http://localhost/democodeigniter/index.php/Mycontroller/file”

You should see something like this:

A simple MVC PHP CodeIgniter Example

Better believe it! You simply made your first page in CodeIgniter.

Recent Posts

error: Alert: Content is protected!!