CodeIgniter - creating forms with .html link - php

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.

Related

How to call one controller(function) view with multiple url in codeigniter via routes.

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.

CodeIgniter link routing

Hi i am new in CodeIgniter. How to give a link to next page like HTML in codeigniter.In HTML we use page name. How to do this thing in codeigniter?
Try using
Some Name
Some Name
I would use base_url() for view files when linking or anchor();
anchor('controller_name', 'Some Name');
anchor('subfolder/controller_name', 'Some Name');
Auto-load the URL helper
You may need to set custom routes for controller Routing In Codeigniter
CI2 & CI3 User Doc's Here. Codeigniter Docs
Goto application >> config >> autoload.php
change line
$autoload['helper'] = array("url");
and change link to
MyLink
'controllername' should be your desired controller name and 'functionname' the same as desired!
You can try so-
Link
CodeIgniter - Correct way to link to another page in a view
codeigniter linking to another page

how to load my default controller in codeigniter using bootstrap?

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.

URI routing in codeigniter

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.

Codeigniter session does not work after including Controller in view

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.

Categories