Truemag

  • Categories
    • Tips And Tricks
    • Internet
    • PHP
    • Javascript
    • CSharp
    • SQL Server
    • Linux
  • Lastest Videos
  • Our Demos
  • About
  • Contact
  • Home
  • Write With Us
  • Job Request
Home PHP CodeIgniter Get Current Controller Function/Action

CodeIgniter Get Current Controller Function/Action

To get current Controller and Function/Action in CodeIgniter, we can call $this->uri->segment(n) of URI Class which is initialized automatically.

CodeIgniter Get Current Controller Function/Action

CodeIgniter Get Current Controller Function/Action

For example:

<?php
	function check_permission()
	{
		/*
		...
		*/
 
		$controller = $this->uri->segment(1);
		$action = $this->uri->segment(2);
 
		/*
		...
		*/
	}
?>

<?php function check_permission() { /* ... */ $controller = $this->uri->segment(1); $action = $this->uri->segment(2); /* ... */ } ?>

Or if we want to retrieve the current controller and function/action in a helper function, we can do this:

<?php
	function check_permission()
	{
		/*
		...
		*/
		$ci = get_instance();
 
		$controller = $ci->uri->segment(1);
		$action = $ci->uri->segment(2);
 
		/*
		...
		*/
	}
?>

<?php function check_permission() { /* ... */ $ci = get_instance(); $controller = $ci->uri->segment(1); $action = $ci->uri->segment(2); /* ... */ } ?>

Oct 21, 2014Hoan Huynh
Top 10 Easy-to-adapt Javascript Frameworks For DevelopersJavaScript Open A New Tab With JQuery
You Might Also Like:
  • Fatal error: Using $this when not in object context
  • Codeigniter Pagination Show Total Pages
  • CodeIgniter Send Email Via SMTP Charset UTF-8
  • CodeIgniter Upload And ReSize Image Maintain Ratio
  • CodeIgniter Save Or Log All MySQL Queries
  • Configure To Run Codeigniter In Sub Folder Or Sub Directory
  • PHP Create Month & Year Drop Down List With Current Month & Year
  • Mysql select current date, current time, current TIMESTAMP example
  • SQL Server get first/last day of previous/current/next month
  • CSharp Validate Email Address Function With Regular Expression
Hoan Huynh

Hoan Huynh is the founder and head of 4rapiddev.com. Reach him at [email protected]

6 years ago PHPCodeigniter, get_instance, segment, URI Class310
0
GooglePlus
0
Facebook
0
Twitter
0
Digg
0
Delicious
0
Stumbleupon
0
Linkedin
0
Pinterest
Most Viewed
PHP Download Image Or File From URL
22,196 views
Notepad Plus Plus Compare Plugin
How To Install Compare Text Plugin In Notepad Plus Plus
20,069 views
Microsoft SQL Server 2008 Attach Remove Log
Delete, Shrink, Eliminate Transaction Log .LDF File
15,847 views
JQuery Allow only numeric characters or only alphabet characters in textbox
13,323 views
C# Read Json From URL And Parse/Deserialize Json
9,815 views
4 Rapid Development is a central page that is targeted at newbie and professional programmers, database administrators, system admin, web masters and bloggers.
Recent Posts
  • Free Online Photo Editor
  • Easy Tips For Writing An Essay
  • What Can I Expect From An Academic Essay Service?

  • Can Be Essay Service Companies Good For You?

  • Tips To Choosing The Ideal Essay Writers
Categories
  • CSharp (45)
  • Facebook Graph API (19)
  • Google API (7)
  • Internet (87)
  • iPhone XCode (8)
  • Javascript (35)
  • Linux (28)
  • MySQL (16)
  • PHP (84)
  • Problem Issue Error (29)
  • Resources (32)
  • SQL Server (25)
  • Timeline (5)
  • Tips And Tricks (141)
  • Uncategorized (112)
Recommended
  • Custom Software Development Company
  • Online Useful Tools
  • Premium Themes
  • VPS
2014 © 4 Rapid Development