how to change the function name in the url using codeigniter?

Multi tool use
Multi tool use


how to change the function name in the url using codeigniter?



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 ,


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>





This will help. codeigniter.com/userguide3/general/routing.html
– Virb
Jul 2 at 5:06





i searched here but did not understood sir can u please explain me how can i achive my desired result
– keerthi patil
Jul 2 at 5:07





change your route like this $route['Blog/blogvieww_all'] = 'Blog/blogvieww';
– pradeep
Jul 2 at 5:09



$route['Blog/blogvieww_all'] = 'Blog/blogvieww';




4 Answers
4



Hope this will help you :



Add the below line of code in your route.php


route.php


$route['Blog/blogvieww_all'] = 'Blog/blogvieww';



Your anchor should be like this :


<a href=<?=site_url('Blog/blogvieww_all');?>





pleasure is mine ,happy codeing
– pradeep
Jul 2 at 5:34





happy coding once again Thank you
– keerthi patil
Jul 2 at 5:35



You can set it through routes of CodeIgniter.


routes



Your path for routes will be application/config/routes.php


routes



See this below may help.


$route['Blog/blogvieww_all'] = 'Blog/blogvieww';



For more detail: https://www.codeigniter.com/userguide3/general/routing.html



1) You can use URI routes. In routes.php, You can specify like below:



$route['Blog/blogvieww_all'] = 'Blog/blogvieww';


$route['Blog/blogvieww_all'] = 'Blog/blogvieww';



Check here for more info.



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.





sir i don want to change the function name in controller i want to change the function anme only in url using routes
– keerthi patil
Jul 2 at 5:09





THen change the route. It would work
– Penguine
Jul 2 at 5:11





LIke this: $route['Blog/blogvieww_all'] = 'Blog/blogvieww';
– Penguine
Jul 2 at 5:12






By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

tA6h KR
Y2tAbZv4fxManOP,WxNn6zZRAuv5hZ UEIPKpQJ

Popular posts from this blog

Rothschild family

Cinema of Italy