-
skyluk Newbie

-
Posts: 3
Threads: 1
Joined: Oct 2016
Reputation:
0
10-15-2016, 04:23 AM
(This post was last modified: 10-21-2016, 05:04 AM by skyluk.)
I accidentally deleted my POST sorry.
I will fix it soon.
-
jlp Senior Member
   
-
Posts: 251
Threads: 151
Joined: Sep 2014
Reputation:
98
You now have the post in the right subforum (I will delete the original), but it still looks like your post is formatting-challenged
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
-
skyluk Newbie

-
Posts: 3
Threads: 1
Joined: Oct 2016
Reputation:
0
10-18-2016, 10:40 PM
(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.
-
skyluk Newbie

-
Posts: 3
Threads: 1
Joined: Oct 2016
Reputation:
0
(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>"; }
}
-
Wouter60 Posting Freak
    
-
Posts: 851
Threads: 38
Joined: Feb 2015
Reputation:
77
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:
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.
|