0% found this document useful (0 votes)
10 views4 pages

2 ND Assignment Major

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
10 views4 pages

2 ND Assignment Major

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 4

Name: Lawrence V.

Sebello Date: September


25, 2024

Year & Section: BTVTED CP3

What is routing?

Network routing is the process of selecting a path across one or more


networks. The principles of routing can apply to any type of network, from
telephone networks to public transportation.
(https://www.cloudflare.com/learning/network-layer/what-is-routing/)

Routes are responsible for responding to URL requests. Routing matches the
URL to the pre-defined routes. If no route match is found then, CodeIgniter
throws a page not found an exception. (https://www.guru99.com/codeigniter-
url-routing.html)

Routing Example:

<?php

$routes->get('journals', 'Blogs');

URI routing?

URI Routing associates a URI with a controller’s method.

CodeIgniter has two kinds of routing. One is Defined Route Routing, and
the other is Auto Routing. With Defined Route Routing, you can define
routes manually. It allows flexible URL. Auto Routing automatically routes
HTTP requests based on conventions and execute the corresponding
controller methods. There is no need to define routes manually.
(https://codeigniter4.github.io/CodeIgniter4/incoming/routing.html#what-is-
uri-routing)

URI routing is the process of taking the requested URI and deciding which
application handler will handle the current request.
(https://webapp2.readthedocs.io/en/latest/guide/routing.html#:~:text=URI
%20routing%20is%20the%20process,will%20handle%20the%20current
%20request.)

Example:

The segments in a URI normally follow this pattern:


example.com/class/function/id/

(https://codeigniter.com/userguide3/general/routing.html?highlight=uri
%20routing)

How to create route?

Routing rules are defined in your application/config/routes.php file. In it


you’ll see an array called $route that permits you to specify your own
routing criteria.

Here are a few routing examples:

$route['journals'] = 'blogs';

A URL containing the word “journals” in the first segment will be remapped
to the “blogs” class.

$route['blog/joe'] = 'blogs/users/34';

(https://codeigniter.com/userguide3/general/routing.html?highlight=route)

How to configure model?

Models are PHP classes that are designed to work with information in your
database. For example, let’s say you use CodeIgniter to manage a blog. You
might have a model class that contains functions to insert, update, and
retrieve your blog data. Here is an example of what such a model class might
look like:
class Blog_model extends CI_Model {
public $title;
public $content;
public $date;
public function get_last_ten_entries()
{
$query = $this->db->get('entries', 10);
return $query->result();
}
public function insert_entry()
{
$this->title = $_POST['title']; // please read the below note
$this->content = $_POST['content'];
$this->date = time();
$this->db->insert('entries', $this);
}
public function update_entry()
{
$this->title = $_POST['title'];
$this->content = $_POST['content'];
$this->date = time();
$this->db->update('entries', $this, array('id' => $_POST['id']));
}
}
How to create controller and view?

A Controller is simply a class file that is named in a way that can be


associated with a URI.

Creating controller:

Let’s create a simple controller so you can see it in action. Using your text
editor, create a file called Blog.php, and put the following code in it:
<?php
class Blog extends CI_Controller {

public function index()


{
echo 'Hello World!';
}
}
Then save the file to your application/controllers/ directory.

Now visit your site using a URL similar to this:

example.com/index.php/blog/

If you did it right, you should see:

Hello World!

(https://codeigniter.com/userguide3/general/controllers.html)

Creating View:

Using your text editor, create a file called blogview.php, and put this in it:
<html>
<head>
<title>My Blog</title>
</head>
<body>
<h1>Welcome to my Blog!</h1>
</body>
</html>
Then save the file in your application/views/ folder.
(https://www.codeigniter.com/userguide2/general/views.html)

You might also like