Welcome Guest, Not a member yet? Register   Sign In
Select tag dropdown dependence to next select tag.
#1

(This post was last modified: 10-21-2016, 05:04 AM by skyluk.)

I accidentally deleted my POST sorry.

I will fix it soon.
Reply
#2

You now have the post in the right subforum (I will delete the original), but it still looks like your post is formatting-challenged Undecided

Have you followed up on any of the StackOverflow suggestions?

From your file naming, it appears that you are using an old version of CI, with lower case controller names. You might update the post to reflect the CI version - it can affect suggestions members have for you.

Just sayin', but having a controller named "models" sounds like a really bad practice.
James Parry
Project Lead
Reply
#3

I would name it CarModels or Car_Models
What did you Try? What did you Get? What did you Expect?

Joined CodeIgniter Community 2009.  ( Skype: insitfx )
Reply
#4

It would help if you share the code of the "add" method in your admin/model controller.
Like jlp said, a controller with the name 'model' is likely to cause confusion because a model is a special type of class within the CodeIgniter framework. Why don't you rename it to "carmodel.php", of (for CI 3.x) "Carmodel.php" ?
Reply
#5

(This post was last modified: 10-19-2016, 08:48 AM by skyluk.)

I am sorry that I m so late to write back.

Thank you all for answers. But I still have same problem.
About controllers names (lowercase). It seems that last time I made a mistake in my post, because in my system - all controller names starting with a capital letter. And I am using latest CI version from a website. I just make a mistake in my post.

Next thing: about naming. Even before I created a "model" controller I was thinking that its not a good practice to name it like that. And i dont know why I did. So sorry, I will change that name today (I will change the name to VehicleModel). Thank you.

Answering to question: "Have you followed up on any of the StackOverflow suggestions?"  Yes, sure. Even in this code I am using the form from suggestion. And I carefully reviewed all other suggestions.
 
And here is my add method from model controller: 

PHP Code:
 public function add(){
        
$this->form_validation->set_rules('vehicleModel''Model','trim|required|min_length[2]' );
        
$this->form_validation->set_rules('brand''Brand''required');
        
$this->form_validation->set_rules('category''Category''required');


        
$data['brands'] = $this->Model_model->get_brands();
        
$data['categories'] = $this->Model_model->get_categories();

        if(
$this->form_validation->run() == FALSE){
            
//Views
            
$data['main_content'] = 'admin/VehicleModels/add';
            
$this->load->view('admin/layouts/main'$data);
        }else{
            
//Create Models data array
            
$data = array(
                
'v_model_name'           => $this->input->post('vehicleModel'),
                
'vehicle_brand_id'       => $this->input->post('brand'),
                
'vehicle_category_id'    => $this->input->post('category')
            );


            
//Model table insert
            
$this->VehicleModel_model->insert($data);
            
/*$this->Brand_model->insert_brand($data);*/

            //create message
            
$this->session->set_flashdata('Model_saved''Your Model has been saved');

            
//redirect to pages
            
redirect('admin/VehicleModels');
        }
        
$value $this->input->post("value");
        
$data $this->VehicleModel_model->get_data($value);
        
$option ="";
        foreach(
$data as $d)
        {
            
$option .= "<option value='".$d->id."' >".$d->v_model_name."</option>";
        }

    } 

Thank you all for a help and sorry for my English. Have a nice day.
Reply
#6

(10-16-2016, 03:22 AM)Wouter60 Wrote: It would help if you share the code of the "add" method in your admin/model controller.
Like jlp said, a controller with the name 'model' is likely to cause confusion because a model is a special type of class within the CodeIgniter framework. Why don't you rename it to "carmodel.php", of (for CI 3.x) "Carmodel.php" ?

Hello, thank you for your kindness. I would be really grateful if you could help me. I am already fix the naming. Now controller name its VehicleModels.php .  And here its "add" method from my VehicleModel controller.  Are you able to help me now? Thank you!  

[/quote]
PHP Code:
public function add(){
        $this->form_validation->set_rules('vehicleModel''Model','trim|required|min_length[2]' );
        $this->form_validation->set_rules('brand''Brand''required');
        $this->form_validation->set_rules('category''Category''required');


        $data['brands'] = $this->Model_model->get_brands();
        $data['categories'] = $this->Model_model->get_categories();

        if($this->form_validation->run() == FALSE){
            //Views
            $data['main_content'] = 'admin/VehicleModels/add';
            $this->load->view('admin/layouts/main'$data);
        }else{
            //Create Models data array
            $data = array(
                'v_model_name'           => $this->input->post('vehicleModel'),
                'vehicle_brand_id'       => $this->input->post('brand'),
                'vehicle_category_id'    => $this->input->post('category')
            );


            //Model table insert
            $this->VehicleModel_model->insert($data);
            /*$this->Brand_model->insert_brand($data);*/

            //create message
            $this->session->set_flashdata('Model_saved''Your Model has been saved');

            //redirect to pages
            redirect('admin/VehicleModels');
        }
        $value $this->input->post("value");
        $data $this->VehicleModel_model->get_data($value);
        $option ="";
        foreach($data as $d)
        {
            $option .= "<option value='".$d->id."' >".$d->v_model_name."</option>";
        }

    
Reply
#7

First, in your view, change this line:
PHP Code:
url "http://paieska.alyvatau.lt/turinio_valdymas/admin/models/add"

into:
PHP Code:
url "<?php echo base_url();?>admin/vehiclemodels/add"

Second, the "add" method should end with an echo statement, because it's an AJAX function.
The return value is then echoed to the calling Ajax request in your view.
So, make sure that at the end of the "add" function you have this:
PHP Code:
echo $option

One more thing: I wonder if camel-case is allowed in controller names. Probably not, so you will have to rename it to Vehiclemodels.php. But you can test it with camel-case first, of course.
Reply




Theme © iAndrew 2016 - Forum software by © MyBB