Welcome Guest, Not a member yet? Register   Sign In
How to display Root Controller Method View?
#1

[eluser]web_developer[/eluser]
Hello Everybody,

I am new user of this forum. And this is my first Post Smile

I have Home Class controller (It is root index class)

Now I have below links need to set (Mostly are static pages)

http://www.test.com/
http://www.test.com/contactus
http://www.test.com/feedback
http://www.test.com/aboutus

Now if some go to feedback page and submit the page then it should come back again to feedback page with "Thank you" Message.

class Home extends Controller {

function Home()
{
parent::Controller();
}

function index()
{
$this->load->view('home_message');
}

function contactus()
{
$this->load->view('contactus');
}

function aboutus()
{
$this->load->view('aboutus');
}

function feedback()
{
$this->load->view('feedback');
}
}


Now What I have to do in feedback method?
and in <form action="/feedback" method="post"> will work? Or I have to
write "/home/feedback" ? then URL will become different.

Can any one explain me? How to handle this thing?

Thanks in advance.
#2

[eluser]CISCK[/eluser]
I think you're looking for something like this:

Code:
// views/feedback.php

<?php if ($_SERVER['REQUEST_METHOD'] == 'POST'): ?>

     <h2>Thank You</h2>

&lt;?php else: ?&gt;

     &lt;!-- put your form code here --&gt;

&lt;?php endif; ?&gt;

Also, don't forget to check out the form helper and validation class.
#3

[eluser]web_developer[/eluser]
Not Exactly..

First I would like to store all fields in DB. and then "Thank you" message.
So I think in controller I have to do some code right ?
#4

[eluser]jedd[/eluser]
Hi web_developer and welcome to the CI forums.

Quote:I have Home Class controller (It is root index class)

It will be easier, as a beginner to CI, if you stick with URLs that include your Controller and Method.

So you would want to go to http://www.test.com/home/feedback rather than http://www.test.com/feedback

Now, from what you've written, I think the answer to your question is the use of flashdata - read about this in the [url="http://ellislab.com/codeigniter/user-guide/libraries/sessions.html"]Session Class[/url] section of the user guide. Alternatively you can use the [url="http://ellislab.com/codeigniter/user-guide/libraries/input.html"]Input Class[/url]. In either case you just want a trigger to notify whether to write your 'thanks for the feedback' message, right?

Rather than use basic HTML form action method stuff - look at the CodeIgniter [url="http://ellislab.com/codeigniter/user-guide/helpers/form_helper.html"]Form Helper[/url]

There are a fair few tutorials - read the wiki for links - that will show you how to do these things.
#5

[eluser]web_developer[/eluser]
Thanks for the info..

I got it the answer from one of the site.

I have to do changes in routes.php file

$route['feedback'] = "home/feedback";

so now my url can work this --&gt; www.test.com/feedback


And in controller I have to manage like below.

function feedback()
{
if(count($_POST) > 0)
{
if(...) // Some Error
{
$this->load->view(‘feedback’);
}
else
{
$data="Feedback Submitted Successfully...";
$this->load->view('feedback',$data);
}
}
else
{
$this->load->view(‘feedback’);
}
}




Theme © iAndrew 2016 - Forum software by © MyBB