[eluser]Crafter[/eluser]
You are on the right track. I suggest you don't rty and complicate thinks. Have another look through the first section of the CI manual, and you will pull through.
So far, you say you have created a controller class CMS. That's fine.
Code:
class Cms extends Controller {
;;;
}
Next you say that you want to allow the CMS class to provide edit functionality.So far so good:
Code:
class Cms extends Controller {
;;;
function editcon() {
:::
}
}
OK, In general your controller function should be doing one or more of the following:
- Getting a request from the user (from the URL)
- Processing the data (eg. validating data, converting, calculating)
- Requesting data from your data storage
- Sending data to your data storage (new or existing data)
- Displaying some user interface items to the user
The forms should be build using the forms component of the CI framework.
All database access should be left to the models.
Your controller should be involved in preparing the data and making the requests.
For example, see if you can follow the code below. I'm not suggesting this is the right way to do it, but understanding what is going on will help you grasp the concepts a bit better.
Code:
function editcon() {
if ($this->input->post('save') ) { // User has pressed save on form
$cms_data['content'] = $this->input->post('content');
$cms_data['description'] = $this->input->post('description');
// Load the model and give it the data to save
$this->load->model('contentmodel');
$this->contentmodel->modify($cms_data);
}
else {
// User is asking for data (from the URL) http://www.mydomain.com/cms/editcon/4
// segment 1 : http://www.mydomain.com
// segment 2: cms
// segment 3: 4
$id = $this->uri->segment(3);
// Request data from the model layer
$this->load->model('contentmodel');
$cms_data = $this->contentmodel->get($id);
// Display the data
$this->load->view('content_form', $cms_data);
}
:::
}