I want to change the function name in the url, i searched for this a lot but unable to find any solution, can any one help me out what should i do consider for example i have a url like
http://localhost/codeIgniter_try/index.php/Blog/blogvieww
,
so here "Blog" is the controller name and "blogvieww" is the function name so if i want to change the function name from "blogvieww" to "blogvieww_all" what can i do?
Blog.php
<?php
defined('BASEPATH') OR exit('No direct script access allowed');
class Blog extends CI_Controller {
public function index()
{
$this->load->view('blogview');
}
public function blogvieww()
{
$this->load->view('blogvieww');
}
}
?>
blogview.php
<html>
<head>
<title>My Blog</title>
</head>
<body>
<div>
<h1>Welcome to my 1st Blog!</h1>
</div>
</body>
</html>
blogvieww.php
<html>
<head>
<title>My Blog</title>
</head>
<body>
<div>
<h1>Welcome to my 2nd Blog!</h1>
</div>
<div>
<h1>Welcome to my 3rd Blog!</h1>
</div>
</body>
</html>
You can set it through routes
of CodeIgniter.
Your path for routes
will be application/config/routes.php
See this below may help.
$route['Blog/blogvieww_all'] = 'Blog/blogvieww';
For more detail: https://www.codeigniter.com/userguide3/general/routing.html
Hope this will help you :
Add the below line of code in your route.php
$route['Blog/blogvieww_all'] = 'Blog/blogvieww';
Your anchor should be like this :
<a href=<?=site_url('Blog/blogvieww_all');?>
1) You can use URI routes. In routes.php, You can specify like below:
$route['Blog/blogvieww_all'] = 'Blog/blogvieww';
2) Write same function again in controller with the name of 'blogvieww_all' .
Change this in your controller:
public function blogvieww()
{
$this->load->view('blogvieww');
}
to
public function blogviewW_all()
{
$this->load->view('blogvieww');
}
You just need to change the name of the function in your controller, to the name you want to display on ur url.
Or
As Pradeep has commented, you can change to routing also. But the best way is to change the function name, unless it is being referenced or called from somewhere else.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.