I have these urls:
How to get controller name, action name from these urls. I’m codeigniter newbie. Are there any helper function to get this info.
You could use the URI Class:
$this->uri->segment(n); // n=1 for controller, n=2 for method, etc
There is an optional second parameter that permits you to set your own default value if the segment is missing. For example, we could use
$controllerName = $this->uri->segment(1, 'magazine');
I’ve also been told that the following work, but am currently unable to test:
The PHP’s popular Framework has some Naming conventions that need to be followed at the time of development.
Controller class names are plural, CamelCased, and end in Controller and the filename would be ‘ApplesController.php’.
e.g. PeopleController and LatestArticlesController
File and Class Name Conventions
In general, filenames match the class names, which are CamelCased. So if you have a class MyNiftyClass, then in CakePHP, the file should be named MyNiftyClass.php. Below are examples of how to name the file for each of the different types of classes you would typically use in a CakePHP application:
- The Controller class KissesAndHugsController would be found in a file namedKissesAndHugsController.php
- The Component class MyHandyComponent would be found in a file named MyHandyComponent.php
- The Model class OptionValue would be found in a file named OptionValue.php
- The Behavior class EspeciallyFunkableBehavior would be found in a file namedEspeciallyFunkableBehavior.php
- The View class SuperSimpleView would be found in a file named SuperSimpleView.php
- The Helper class BestEverHelper would be found in a file named BestEverHelper.php
Each file would be located in the appropriate folder in your app folder. Continue reading
Implementing Google login system in your website is very easy with OAuth2 support, a simple and standard authorization method. With minimal line of PHP codes, we can acquire required user information from Google, and use the information to register or login users on click of a button. In this article let us learn to easily register/login users using Google PHP API library and MySQL.
This tutorial requires only one PHP page, all task are performed within the page with support of Google APIs Client Library for PHP. These library files are included in downloadable file at the bottom of this page, also look at their sample code, because this tutorial is based on it.
Run SQL query below to create a new MySQL table called “google_users” using phpMyAdmin. There are five columns in the database table for the tutorial, and you will find that the length of Google profile IDs are too long (21 characters), it is not possible to accommodate these IDs into INT or BIGINT field, hence I have used DECIMAL(21,0), but you can also store them as string in VARCHAR field and create a separate auto increment primary field.
CREATE TABLE IF NOT EXISTS `google_users` (
`google_id` decimal(21,0) NOT NULL,
`google_name` varchar(60) NOT NULL,
`google_email` varchar(60) NOT NULL,
`google_link` varchar(60) NOT NULL,
`google_picture_link` varchar(60) NOT NULL,
PRIMARY KEY (`google_id`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1;