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.
Related
I generated a project using, phalcon tools. In the config.php I changes view to:
'viewsDir' => APP_PATH . '/views/test/',
I have created two controllers: ExampleController and TestController
I have links pointing to http://example.com/test and http://example.com/test
In the views folder I have placed 2 files, one in views/test/example/example.phtml and another in views/test/test/test.phtml when I try to go to the links I get a blank page, if I move the phtml files in folder views/test/ the view that is loaded is the index.phml no matter which of the 2 url's I go to (this is the page that displays the 2 links above). If I echo out from the controllers this is displayed so the controllers are being accessed just the view are not being displayed. Please can someone advise? (Nb. If I use the default view configuration, then the views are being displayed)
You should place an index.phtml file in both directories. Thats the page that's loaded once you point to the respective controller. If you want it to load e.g example.phtml, you have to create an action called exampleAction in ExampleController. Then call it via http://example.com/example/example.
I create a controller function home/index .
calling vai url it is showing me html design.
I want to call the view of home/index via custom urls.
If I type
www.example.com/home_new // it will open view of home/index
www.example.com/home_new1 // it will open view of home/index
Also i want to save the custum urls in database so that admin can change.
Please advise how to do this via routes or another method.
Add this code to inside route.php file:
$route['home_new'] = 'home/index';
$route['home_new1'] = 'home/index';
This will solve your problem. For database it will not help you.
You can take reference from this link.
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 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.
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.