Where is ci controller
Since your controller classes will extend the main application controller you must be careful not to name your functions identically to the ones used by that class, otherwise your local functions will override them. See Reserved Names for a full list. CodeIgniter User Guide Version 2. Controllers Controllers are the heart of your application, as they determine how HTTP requests should be handled.
What is a Controller? Consider this URI: example. When a controller's name matches the first segment of a URI, it will be loaded. Let's try it: Hello World! Now visit the your site using a URL similar to this: example. Note: Class names must start with an uppercase letter. Functions In the above example the function name is index. Another way to show your "Hello World" message would be this: example.
Let's try it. For example, lets say you have a URI like this: example. Remapping Function Calls As noted above, the second segment of the URI typically determines which function in the controller gets called. Private Functions In some cases you may want certain functions hidden from public access.
Reserved Function Names Since your controller classes will extend the main application controller you must be careful not to name your functions identically to the ones used by that class, otherwise your local functions will override them. Visiting the second URI in the browser, we get the same output as shown in the above picture. Visiting the third URI in the browser, we get the output as shown in picture given below.
This can be a simple or complex webpage, which can be called by the controller. The webpage may contain header, footer, sidebar etc. View cannot be called directly. Let us create a simple view. Where name is the view file, which is being rendered. Models classes are designed to work with information in the database.
Following code shows how to create model class in CodeIgniter. The first letter of the model class must be in capital letter. The class name and file name must be same. After loading the model you can simply call its method as shown below. There may be situations where you want some model class throughout your application.
In such situations, it is better if we autoload it. As shown in the above figure, pass the name of the model in the array that you want to autoload and it will be autoloaded, while system is in initialization state and is accessible throughout the application. As the name suggests, it will help you build your system. It is divided into small functions to serve different functionality. A number of helpers are available in CodeIgniter, which are listed in the table below.
We can build our own helpers too. Each helper, whether it is custom or system helper, must be loaded before using it. The Email Helper provides some assistive functions for working with Email.
The Inflector Helper file contains functions that permits you to change words to plural, singular, camel case, etc. The Typography Helper file contains functions that help your format text in semantically relevant ways. If you intend to use a constructor in any of your Controllers, you MUST place the following line of code in it:.
The reason this line is necessary is because your local constructor will be overriding the one in the parent controller class so we need to manually call it. Constructors are useful if you need to set some default values, or run a default process when your class is instantiated. Since your controller classes will extend the main application controller you must be careful not to name your methods identically to the ones used by that class, otherwise your local functions will override them.
See Reserved Names for a full list. You should also never have a method named identically to its class name. Index::index method will be executed as a class constructor! This is a PHP4 backwards-compatibility feature. Docs » General Topics » Controllers. Page Contents Controllers What is a Controller? What is a Controller? Consider this URI: example. Important Class names must start with an uppercase letter.
Important If you are using the URI Routing feature, the segments passed to your method will be the re-routed ones.
0コメント