This is one of those things that just makes me feel like an idjut.
Ok - so I am just starting out with Codeigniter and I just am having a hell of a time getting my head around the URL system.
Here are some relevant config settings up front ( and I'm on MAMP/localhost at the moment )
$config['base_url'] = 'http://localhost:8888/MY_SITE/';
$config['index_page'] = 'index.php';
$route['default_controller'] = "home";
My .htaccess file is blank as of now.
So I have a "home" controller, which I hit fine, and it loads my "home_view". On it I have a registration link ...
<p>Not a member yet? Sign Up!</p>
This renders as the following HTML ...
Sign Up!
Everything fine so far. But when I click I get a "404 Page Not Found". I have a "registration.php" controller with an index method that loads a "registration_view.php".
This is what is showing in my address bar
http://localhost:8888/MY_SITE/index.php/registration
Why do I not hit it?
My logs show ..
ERROR - 2012-11-13 18:21:12 --> 404 Page Not Found --> registration/index
.. WHY DOES FATE HATE ME SO?
One of many possible and most close reason for 404 might be that there's no index() function in your controller. Can u post the code??
EDIT ( Since ans got downvote ) I have to give more explanations.
In this case possible reasons for 404 error can be -
Your default controller is set home and the url on which your are getting 404 is calling registration controller.
If there's no registration controller you get 404.
If there's no function named as registration present in your default home controller.
First arguement in URI (after index.php [if htaccess is not used to remove index.php] ) is for controller that will be called. And second argument after index.php is function that will be called from controller mentioned in first argument. In both cases, ie controller and function not present you get 404.
If registration is function and it's visibility is set to private then you get 404.
Just for note, to make URLs more readable you should include htaccess and add rules to remove index.php.
Related
I have "Front page displays" set to "Your latest posts" in the Settings > Reading section of the Wordpress dashboard and I want to use front-page.php as my landing page.
I don't really have any use for index.php outside of it being a fallback. I guess as a fallback, I'd just want to display the home page, so I just included front-page.php in index.php:
index.php
<?php include('front-page.php'); ?>
The problem is that inside of front-page.php, I have some actions running.
front-page.php
<?php do_action('myaction'); ?>
When I load the site, front-page.php, these actions all seem to be running twice. Why are actions on index.php running when front-page.php is being loaded?
This lead me to remove the include() statement inside index.php and just use an empty index.php file. That can't be right though? Why are these actions running twice when the page loads?
WordPress uses a .htaccess file to redirect all request to index.php, which then loads the wanted page.
In your case, this means going to /front-page.php first loads index.php which then loads front-page.php.
In order to redirect to front-page.php, I would suggest you to do the following steps in index.php:
Look if the current url is index.php
If we're on the index, send a redirect header Header("Location: front-page.php"); followed by exit or die.
If not, keep loading as usual
You can always place some "test" text in the file you suspect may be loading to make sure you're seeing the correct file. Just put TEST or something in the file and see if it shows on screen. Now you know which file is loading.
It will default to index.php many times if you're intended file isn't coded right or if it's named improperly. I have had this issue before!
i have a view with bootstrap template which is embedded at my view/reportlist.php (localhost/Project/index.php). the problem is that every time i perform a CRUD, well codeigniter reroutes me to deffirent uri. example, when i edit a report from my list, i will be redirected to my view/reportlist.php (/Project/index.php/report/edit). then my bootstrap template is ruined. i need to go back to the /Project/index.php to load back everything up. please if you know, post some ideas, ive been like this for days now, i cant find a relevant answer.
there is no relation between codeigniter route and bootstrap. you can set you default controller in line 41 in: application > config > route.php file.
on ther other hand you can set you base_url in line 17 in: application > config > config.php by this:
$config['base_url'] = "http://".$_SERVER['HTTP_HOST'];
$config['base_url'] .= preg_replace('#/+$#','',dirname($_SERVER['SCRIPT_NAME'])).'/';
I'm sure that you have call again the list view in you edit method in report controller :D .
if you want to avoid index.php from you url then you can modify code in your .htdocs files:
In your form action attribute specify a route: <?php echo base_url('/someRoute'); ?>, and in routes.php map it to some specific controller: $route['someRoute'] = 'home/someRoute';, from this controller load your desired view.
As the title suggests, my issue is with codeIgniter.
I have used a code in an .htaccess file to remove index.php which works all OK.
But I need to go further in changing the URI:
My main controller is page(), so when a user is in my homepage, the URL-bar shows:
www.example.com/page/
(because homepage is index page, it does not show the page name as usual the controller suffice),
but If I go to registration page, the URL-bar shows:
www.example.com/page/register
Up to here everything is OK, but I want the codeIgniter to show my domain without the page() when the user is in my homepage, I don't want foolish www.example.com/page/ to appear and I think when someone is visiting index page, the URL-bar better to be www.example.com
You can define a custom route in config/routes.php - for example:
$route['default_controller'] = 'page';
Then, http://example.com
goes to http://example.com/page
then if you did not specify any data , it will route to default controller.
for the link to register:
www.example.com/register
in config/routes.php
$route['register'] = 'page/register';
You have everything explained here in great detail.
http://ellislab.com/codeigniter/user-guide/tutorial/static_pages.html there is an example here on the bottom how to do uri routing with routes.php file in codeigniter.
I was working on a site in which on right side I am displaying some fixed type of dynamic content like event calendar, login, register etc. right side bar name is right_view.php
So first I was doing like this that I was sending parameters in every function of controller's and then in my view I was accessing right side parameters by calling right view like this
<?php $this->load->view('right_view');?>
then after login I can get my username that is stored in session.
After that I thought it is not a good approach to send parameters in every functions I just make a controller named right.php and in this controller I am passing parameters to right_view.php and after that in my view I changed my code for callig righr_view like this
<?php include(base_url().'right');?>
It display right content as I do above but one changed happen that I cannot access any of session stored variable in right side bar.
Is session does not work after including controller in view?
You're basically wanting to do a template system but going about it the wrong way. And for the record no I don't think you can (or at least should) be loading controllers into views like that.
What you want is a template file something like this:
<?php
$this->load->view('templates/header', $title);
$this->load->view('templates/sidebar',$sidebar_content);
$this->load->view('pages/'.$main_content);
$this->load->view('templates/footer');
?>
Call that template.php
Then in your controller you'd do something like this:
public function welcome()
{
$data['main_content'] = 'welcome';
$data['title']='Welcome to REfficient.com!';
$data['sidebar_content'] = 'sidebar/no_sidebar';
$data['additionalHeadInfo'] ='';
$this->load->view('templates/template',$data);
}
So if you look at the template file the first line is loading the header and including the title variable to insert into the page (header, sidebar, maincontent and footer are all their own separate PHP pages) and so on.
Now what I did (since my layout was very similar to yours) is my main sidebar file has an if statement that says if logged in show x, if not show login form.
Note - the additionalHeadInfo variable is so I can have includes like jQueryUI or something on an individual page without loading it on pages that don't need it.
I want to create a simple website with 5 pages which contains 2 simple contact us forms.
The links should be www.yoursite.com/contact.html and after submitting it should go to www.yoursite.com/success.html. Please help, I have searched a lot for it but couldn't find anything
[edit]
I have a different controllers for different forms but in the links i don't want the controller name but only the view name.html
If all you want to do is change the apperance of the URLs, then you could use CodeIgniter's routing. You'll most likely also want to remove index.php from the URL, more information is available in CodeIgniter's user guide.
For example, if you have a controller named Contact with an index() function that loads the view for the contact form, and another function success() that loads the success page view:
Then this route, in application/config/routes.php would map the URL, www.yoursite.com/contact.html to your Contact controller.
$route['contact.html'] = "contact";
This route would map www.yoursite.com/success.html to the success() function within the Contact controller.
$route['success.html'] = "contact/success";
If you want your Codeigniter URLs to have ".html" appended to them for some reason, you should modify your application\config\config.php file and change
$config['url_suffix'] = '';
to
$config['url_suffix'] = '.html';
You can see here for more info.