Welcome Guest, Not a member yet? Register   Sign In
Reload page with id in url
#1

[eluser]Unknown[/eluser]
Hi all!
On this site that I'm coding I have a page that is accessible through the following urls:
Code:
http://site.com/campaigns/view/
which displays a default view of all campaigns and
Code:
http://site.com/campaigns/view/8
which displays details for campaign 8

On this page I have a form from which you can add subscribers a the specific campaign.
My controller logic goes something like this:
Code:
$campaign_id = $this -> uri -> segment(3);
$this -> campaign_model -> get_campaign_details(3);

// Form was submitted
if ($this -> input -> post()) {
    //code to check inputs and save subscriber
} else {
    // Display page with campaign details
}

Now my problem is, in the else branch, how would I go about displaying the page with the campaign details. I've tried
Code:
redirect("campaigns/view/8")
which creates a redirect loop and also
Code:
$this -> load -> view("campaigns/view/".$campaign_id)
which of course tries to load a view 8.php that doesn't exist.
So how would I go about implementing the functionality for something like this?

Thanks in advance!
Jim
#2

[eluser]phpLearner[/eluser]
save the users id in flashdata and redirect the page, collect flashdata and show appropriate view.

for more details on flashdata see sessions in codeigniter userguide
#3

[eluser]boltsabre[/eluser]
What does the user id have to do with this???

What you could do is inside the the "else" part is check the http referrer, and if it's the same as the current page do NOT redirect (because you're already there!) but if it is different then you could run the redirect as they are trying to access the page from somewhere else.

But isn't it the same page that's being displayed regardless of if the form is submitted or not? Why not just load the view at the end of your function like this:

Code:
$campaign_id = $this -> uri -> segment(3);
$this -> campaign_model -> get_campaign_details(3);

// Form was submitted
if ($this -> input -> post()) {
    //code to check inputs and save subscriber
}
$this->load->view('some_view', $data);

And shouldn't this:
Code:
$campaign_id = $this -> uri -> segment(3);
$this -> campaign_model -> get_campaign_details(3);

Actually be:
Code:
$campaign_id = $this -> uri -> segment(3);
$this -> campaign_model -> get_campaign_details($campaign_id);

// Or even more simple, just this:
$this -> campaign_model -> get_campaign_details($this -> uri -> segment(3));




Theme © iAndrew 2016 - Forum software by © MyBB