Welcome Guest, Not a member yet? Register   Sign In
addcomment function
#1

[eluser]junaids[/eluser]
hi
i have a page with url like
http://localhost/codeigniter/index.php/e...iewevent/8

it shows an event detail from the DB. the page has a textarea to add comments. on submittion addcomment() function is called in the contrller. Now i need to know in my controller to which event i have to add comments. i am using code like.
Code:
$Event_id = $this->uri->segment(3, 0);

but it is giving me Event_id= 0 every time, which should be 8 in this case.
any suggestions?
#2

[eluser]Dam1an[/eluser]
The reason it's returning 0 is cause it's technically a differant URL by the time it gets processed (you go to a differant URl when processing the form)

You can either set the ID as a hidden field in the form so you can access it as a post variable
Or add the ID to the path of the process function like so:
Code:
<?=form_open('events/addcomment/'.$this->uri->segment(3, 0))?>
Or instead of getting the URI segment, you can use it as a function parameter called event_id and use that
#3

[eluser]junaids[/eluser]
thanx.. hidden field is working well.
#4

[eluser]junaids[/eluser]
i again have a problem of same kind.
first i used the hidden field with the form and it was working all right.
now i am not using a form...instead i m using a anchor to refer the user to another page.
so if i am on a page like..

http://localhost/codeigniter/index.php/c...ommunity/2

and the user clicks an anchor on this page which calls a function like..

http://localhost/codeigniter/index.php/c...eatethread

how in this function createthread() i can know from which community did the user clicked this link..like community_id = 2 in this case..?

Dam1an mentioned using a function parameter instead of uri segment..if any one can explain that...
#5

[eluser]Dam1an[/eluser]
So you create the anchor in much the same way as I showed with the form earlier and then you read the user guide on passing paramters into functions
#6

[eluser]junaids[/eluser]
ok..
i got it right till this url..
http://localhost/codeigniter/index.php/c...tethread/2

i used anchor for it which is like..
Code:
site_url('communities/createthread/'.$this->uri->segment(3, 0))


i got the community_id with the url..it is supposed to be passed to the function as a parameter..as i read from the user guide..
but it is not passed and i mm getting an error when i post the form...

Message: Missing argument 1 for Communities::createthread()

i post my controller function createthread here
Code:
function createthread($Community_ID)
     {
        $data['css'] = $this->css;
          $data['base'] = $this->base;
            $Community_id = $Community_ID;
        $this->validation->set_error_delimiters('<div class="error">', '</div>');
        if(!$this->input->post()):
            $rules['subject']    = "required";
            $rules['message']    = "required";
            $this->validation->set_rules($rules);
        $fields['subject'] = 'Thread subject';
        $fields['message'] = 'Thread message';
        
            $this->validation->set_fields($fields);
            if ($this->validation->run() == FALSE) {
                $this->load->view('communities/newthread');
            }
            else {
                $id = $this->communitymodel->addthread($Community_ID);
                $uri ='communities/viewthread/'.$id;
                redirect($uri);
            }
        else:
                $this->load->view('newthread');
        endif;
        
    }




Theme © iAndrew 2016 - Forum software by © MyBB