How I can get application base URL in view template file?
I am using CodeIgniter-3.1.6 to build an application.
You need to load the URL helper (usually done in a controller or model):
$this->load->helper('url');
Then your base URL is available in the view like this:
echo base_url();
Related
When I enter the url mysite/home it goes to a php page called register.php. Where can I specify that it goes to login.php instead? Thanks
In application/config/routes.php look for $route['default_controller']
Set its value to the desired controller name you wish to used as default (only controller, no method). By default, users that go to your base url will be shown whatever is at name_of_controller_you_chose/index
I wanted to create a folder named 'schoollevel' inside controller and view folder to create a separate module containing login function and profile views to provide another login functionality for some users. The 'schoollevel' contains all the files for login and profile view. Can anyone suggest how to do this ? I want the control to go to the separate folder.
Its Easy to create folder in controller and view in codeigniter.
Folder name : school
1.create a login controller
application->controller->school->Login.php
create a login view
application->view->school->login.php
Now, How to call view file
Inside login controller in the index() function add
this to call login.php view
$this->load->view('school/login');
I hope this help you!
I have developed a website with PHP Codeigniter. It consists of many controllers and views. I want to encrypt the URL of the site to hide the controller and function name. Currently, the URL looks like this :
www.sitename.com/controller_name/function_name
I don't want the users to see the controller and function names. Is it possible to do this now because the site is almost complete. Is there any shortcut of doing this? Please Help
You can use codeigniter URI Routing to remove your controller name from URL.
$route['url_name'] = 'controller_name/function_name';
This `www.sitename.com/url_name` will look go to `www.sitename.com/controller_name/function_name`
$route['url_name/(:any)'] = 'controller_name/$1';
This will only change your controller name.. `controller_name` to `url_name`
I uploaded CodeIgniter in my server, and the basic page works fine.
Then I added home.php file in application/controllers folder with class Hello and function one, and tried to open the link url/index.php/Hello/one but I get the codeIgniter error that the page isn't found. What can I be missing?
To fix your issue you should rename the Hello class to Home then go to URL/index.php/home/one
I recommend that you read up on the controller documentation:
http://ellislab.com/codeigniter/user-guide/general/controllers.html
A Controller is simply a class file that is named in a way that can be
associated with a URI.
Consider this URI: example.com/index.php/blog/
In the above example, CodeIgniter would attempt to find a controller
named blog.php and load it.
When a controller's name matches the first segment of a URI, it will
be loaded.
Actually m using ahref with onclick function inside my view
<a href="<? echo base_url();?>index.php/manager/engineer" onclick=window.open("<? echo base_url();?>index.php/manager/engineer") >
it is redirecting to url correctly
http://localhost:8888/CI/index.php/manager/engineer
but in that page m getting error as
The page you requested was not found.
even though i have created engineers view file
Anyone helping me to find the solution will be needfull
the CI router just run external links of controller classes and you can't load views externally. instead on you can load views internally on your controllers and now open the controller address via your browsers.
see more : http://ellislab.com/codeigniter/user-guide/general/views.html