Welcome Guest, Not a member yet? Register   Sign In
How to pass multiple values from view->controller->model
#11

[eluser]johnmiller[/eluser]
i have gone through user guide..

i have tried many ways...

but i didn't get the answer...

can you help me???
#12

[eluser]Eric Cope[/eluser]
what calls the view the for the first access? Call it with the controller that you are using to validate it.

use 'blog/do_search'
#13

[eluser]johnmiller[/eluser]
in the controller, i use the below function to load the search page for the first time.

Code:
function search()
    {  
        $this->load->model('location_model');
        $this->load->model('team_model');
        $this->load->model('organization_model');
        $data['query_state'] = $this->location_model->select_all_states();
        $data['query_city'] = $this->location_model->select_all_cities();
        $data['query_team'] = $this->team_model->select_all_teams();
        $data['query_org'] = $this->organization_model->select_all_org();
        $data['query_org_type'] = $this->organization_model->select_all_org_types();
        $this->load->view('search', $data);
    }

after search button click, i use another function in controller

that function is
Code:
function do_search()
    {

    $this->validation->set_error_delimiters('<div id="errorLogin">', '</div>');
    $rules['fname'] = "trim|required|max_length[100]|xss_clean";
    $this->validation->set_rules($rules);
    $fields['fname'] = "First Name";
    $this->validation->set_fields($fields);
    if($this->validation->run() == FALSE)
    {
        $this->load->view('search');
    }
    else{
        
        $fname = $this->validation->fname;
        $this->load->model('search_model');
        $data['search_details'] = $this->search_model->search_students($fname);
        $this->load->view('search_results', $data);
    }

    }


so where i should write the library???

in the search function?

what all things I should add?

i am getting the error in the view page...

means... in the first load..

that means... we have to add the library in search function, right?

what i should write there?
#14

[eluser]Eric Cope[/eluser]
You do not need two controllers. Call do_search. Since there is not Post data, it will fail to validate, but no error messages will be generated. The View page will look as if it should upon first entering.

Code:
function do_search()
    {

    $this->validation->set_error_delimiters('<div id="errorLogin">', '</div>');
    $rules['fname'] = "trim|required|max_length[100]|xss_clean";
    $this->validation->set_rules($rules);
    $fields['fname'] = "First Name";
    $this->validation->set_fields($fields);
    if($this->validation->run() == FALSE)
    {
        $this->load->model('location_model');
        $this->load->model('team_model');
        $this->load->model('organization_model');
        $data['query_state'] = $this->location_model->select_all_states();
        $data['query_city'] = $this->location_model->select_all_cities();
        $data['query_team'] = $this->team_model->select_all_teams();
        $data['query_org'] = $this->organization_model->select_all_org();
        $data['query_org_type'] = $this->organization_model->select_all_org_types();
        $this->load->view('search');
    }
    else{
        $fname = $this->validation->fname;
        $this->load->model('search_model');
        $data['search_details'] = $this->search_model->search_students($fname);
        $this->load->view('search_results', $data);
    }
}
#15

[eluser]johnmiller[/eluser]
i tried that...

now i have only one function in my controller for search

that is

Code:
function do_search()
    {

    $this->validation->set_error_delimiters('<div id="errorLogin">', '</div>');
    $rules['fname'] = "trim|required|max_length[100]|xss_clean";
    $this->validation->set_rules($rules);
    $fields['fname'] = "First Name";
    $this->validation->set_fields($fields);
    if($this->validation->run() == FALSE)
    {
        $this->load->model('location_model');
        $this->load->model('team_model');
        $this->load->model('organization_model');
        $data['query_state'] = $this->location_model->select_all_states();
        $data['query_city'] = $this->location_model->select_all_cities();
        $data['query_team'] = $this->team_model->select_all_teams();
        $data['query_org'] = $this->organization_model->select_all_org();
        $data['query_org_type'] = $this->organization_model->select_all_org_types();
        $this->load->view('search');
    }
    else{
        $fname = $this->validation->fname;
        $this->load->model('search_model');
        $data['search_details'] = $this->search_model->search_students($fname);
        $this->load->view('search_results', $data);
    }


and when i try to load my search page, it is not at all loading..

i am getting an error message like

Code:
Severity: Notice

Message: Undefined property: Blog::$validation

Filename: controllers/blog.php

Line Number: 34


Line number 34 is
Code:
$this->validation->set_error_delimiters('<div id="errorLogin">', '</div>');
#16

[eluser]johnmiller[/eluser]
i have changed the do_search function to

Code:
function do_search()
    {
    $this->load->helper(array('form', 'url')); //added
    $this->load->library('validation');        //added

    $this->validation->set_error_delimiters('<div id="errorLogin">', '</div>');
    $rules['fname'] = "trim|required|max_length[100]|xss_clean";
    $this->validation->set_rules($rules);
    $fields['fname'] = "First Name";
    $this->validation->set_fields($fields);
    if($this->validation->run() == FALSE)
    {
        $this->load->model('location_model');
        $this->load->model('team_model');
        $this->load->model('organization_model');
        $data['query_state'] = $this->location_model->select_all_states();
        $data['query_city'] = $this->location_model->select_all_cities();
        $data['query_team'] = $this->team_model->select_all_teams();
        $data['query_org'] = $this->organization_model->select_all_org();
        $data['query_org_type'] = $this->organization_model->select_all_org_types();

        $this->load->view('search', $data); //$data was not given before
    }
    else{
        $fname = $this->validation->fname;
        $this->load->model('search_model');
        $data['search_details'] = $this->search_model->search_students($fname);
        $this->load->view('search_results', $data);
    }

now the search loads without any problem...

but nothing happens when i enter some value in the textbox and click search button...

what could be the problem???
#17

[eluser]Rick Jolly[/eluser]
[quote author="johnmiller" date="1218160491"]
how to load the validation library???
[/quote]

[quote author="johnmiller" date="1218161669"]i have gone through user guide..

i have tried many ways...

but i didn't get the answer...

can you help me???[/quote]

Did you really just ask: "how do I load a library"?
#18

[eluser]johnmiller[/eluser]
why nothing happens in the search button click???

any idea???
#19

[eluser]Rick Jolly[/eluser]
I'd rather not be your personal user guide search engine.

But I'm compelled to answer: User Guide > General Topics > Using CodeIgniter Libraries.
#20

[eluser]johnmiller[/eluser]
i have added
Code:
$this->load->library('validation');
in my function do_search (in controller)

the page loads without any problem.

when i click the button, the else condition in the do_search function should work.

but nothing happens...




Theme © iAndrew 2016 - Forum software by © MyBB