This is probably a really simple question but I am entirely new to codeigniter. I am using ionauth for a secure account system but I would like to change the url path, simply changing the class name is not working, it simply gives me a 404 whenever I try access it. I am trying to change the /auth/ location to /account/ but when I try it by just renaming class Auth extends CI_Controller { to class Account extends CI_Controller { it does not work as expected.
Any suggestions are greatly appreciated,
Again I am new to this so please go easy it's probably a simple fix and me not know code igniter very well.
Thanks,
Simon
From application/config/config.php file ,you can set your base URL.Base URL should be absolute, including the protocol:
$config['base_url'] = "http://somesite.com/somedir/";
If using the URL helper, then base_url() will output the above string.
For url routing you can use like this $route['account/login'] = "auth/login"
Related
I want to manage my url in codeigniter...
where my frontend should be like this
"http://www.Himalayi.com/" and the
admin panel should be http://www.Himalayi.com/__admin
I am not able to manage though i've tried alot..
the folder structure is given below
Please
Help me.. Thanks
application/
controller/admin/home_banner.php,user.php
model/admin/model_home_banner.php, model_user.php
view/admin/home_banner/add.php
and
in the same folder controller i have
frontend folder the file is welcome.php!
how to manage in config, routes, htaccess
I do not know why you would want to prepend underscores to access the admin panel. Please keep in mind that defining controller functions like:
public function _notReachable(){
#do something
}
will result in an inaccessible function regarding web requests.
So calling example.com/home/_notReachable will not work.
Maybe that already solves your problem?
See codeigniter documentation "Controllers - private Functions".
I am new to codeigniter and really interested in trying it out. I followed the guide but ran into a problem. It seems like I am unable to load my first page properly.
I have inside the view folder another folder called general and inside it index.php.
in controller folder, I have sub-folder with general and inside it is Default controller.
I have the following route and yet the page showing is blank
$route['default_controller'] = "general/default";
$route['404_override'] = '';
When I visit the link, I type this in browser:
http://localhost:8888/treventa/
and the screen is blank. Am I doing something wrong? Sorry if this is too simple but a person got to learn from his mistake :)
Try with me step by step:
Firstly: the Controller:
(main.php) File content
if (!defined('BASEPATH'))exit('No direct script access allowed');
class Main extends CI_Controller {
public function index() {
$this->load->view('general/welcome');
}
}
Secondly: The view:
(welcome.php) File content
You can put anything you want
<h1> Hello, I'm the view file </h1>
Finaly: The routes:
(routes.php) File content
$route['default_controller'] = "general/main";
Now call the script like this http://localhost/codeIgniter/, that's where codeIgniter is the script folder name.
I think everything now is clear.
CI trying to use method default() of general controller. If You want to use folders for controllers, make sure You specify method, so try $route['default_controller'] = "general/default/index";
And one more thing: this method (default_controller) will be used when You trying reach Your root http://localhost:8888/, if You want to route request from http://localhost:8888/treventa/ to default controller, You need to add route-rule to /config/routes.php something like $route['treventa'] = "general/main/index";
In my routes.php I have :
$route['default_controller'] = "bitcoin";
and in my config.php I have:
$config['base_url'] = 'http://localhost/bitcoin/';
$config['index_page'] = 'index.php';
here is my controller: http://www.pastie.org/2253458
When I try to go to the following, I get a 404 not found (but the 404 template looks different):
http://localhost/bitcoin/edit/
http://localhost/bitcoin/index.php/edit
You can't access functions through the default controller like this.. It's assumes your trying to access another controller. Default controller is used when nothing is passed, ie: index.php
You will need to go to /bitcoin/index.php/bitcoin/edit
And note you will only be able to go to /bitcoin/bitcoin/edit if you have a htaccess file setup for routing.
You didn't say if you've removed or not your index with .htaccess, but if you didn't, did you try using: http://localhost/index.php/bitcoin ?
Or better, since it's your default controller, just http://localhost ?
What you're doing is quite strange, I can't understand if you're in a subfolder called bitcoin (in case, it should be http://localhost/bitcoin/ to call the default controller, which is also called bitcoin but doesn't need to be indicated in your URL).
If you're in root, You should rewrite your urls as: http://localhost/index.php/bitcoin/edit to call the edit() method of your default controller
Edit:
If you're in a subfolder called bitcoin, your base url, with default controller, should be:
http://localhost/bitcoin/ (which is the same as http://localhost/bitcoin/index.php/bitcoin)
If you want to get the bitcoin method edit(), should be http://localhost/bitcoin/index.php/bitcoin/edit
Also, try removing your .htaccess AT ALL and see what happens.
Edit2
Oh, one last thing: use CI_Controller and not CI_controller, if you're on a OS where lowercase matters you might encounter some problems
A newbie here: sorry if the question is too simple, been looking in tutorials but I don't seem to look properly.
I have the
$route['default_controller'] = "mainpage";
in routes.php working properly, and now I just want to view one of the php pages in views folder by typing its url:
http://myserver/folder/thepageIwantToSee
I get a 404 Not Found error. Do I have to use a controller? I just want to see it first before any linking, is there a way to do it?
Thanks a lot!
class yourcontroller extends CI_Controller {
function pageiwanttosee()
{
code
code
$this->load->view('the_view_page', $data);
}
}
Yes, you can write a controller that displays the view specified.
http://myserver/showfile/folder/thepageIwantToSee , where showfile is your controller.
Don't forget to set some security check or disable this on production site.
I'm hoping that this will be a simple question that someone can answer. I'm looking to build a CodeIgniter application that I can build pretty easily in regular PHP.
Example: I would like to go to http://locahost/gregavola and have rewritten using htaccess file to profile.php?user=gregavola. How can I do this in CodeIgniter?
Usually in htaccess I could write ^(\w+)$ profile.php?user=$1 but that won't work with the paths in CodeIgniter.
Any suggestions?
CodeIgniter turns off GET parameters by default; instead of rewriting the URL to a traditional GET style (IE, with the ?), you should create a user controller and send the request to:
http://localhost/user/info/gregavola
Then in the user controller, add the following stub:
function info($name)
{
echo $name;
}
From here you would probably want to create a view and pass $name into it:
$data['name'] = 'Your title';
$this->load->view('user_info', $data);
You can find all of this in the CodeIgniter User Guide, which is an excellent resource for getting started.
To map localhost/gregavola to a given controller and function, modify the routes file at application/config/routes.php like so:
$route['(:any)'] = "user/info/$1"
Routes are run in the order they are received, so if you have other routes like localhost/application/dosomething/, you will want to include those routes first so that every page in your entire app doesn't become a user page.
Read more about CI routes here: http://codeigniter.com/user_guide/general/routing.html
Good luck!