Welcome Guest, Not a member yet? Register   Sign In
Message: Undefined variable [Resolved]
#1

[eluser]Sebish[/eluser]
Hey, I realise that there is a million different threads relating to this subject matter, but I just cant seem to figure it out. I have got edit, create and delete functions working fine, however I'm trying to make one which is called update (which is based of edit, but its editing separate data from the same database table.

So basiclly I have setup this update_checklist model that should be working exactly the same as the edit_checklist model, however the update_checklist makes use of checkboxes where the other one doesn't. When in the view, it feeds back an error.

Quote:A PHP Error was encountered

Severity: Notice

Message: Undefined variable: checklist

Filename: checklists/development.php

Line Number: 47

I have dealt with this in the past, but for some reason I just can't seem to figure this out. I will post up my Controller, Model, and View and if anyone could point me in the right direction it would be fantastic!

Controller:

Code:
<?php

class Checklists extends Controller
{
    function Checklists()
    {
        parent::Controller();
            
        $this->access_library->check_access();
        
        $this->load->module_model('admin', 'checklists_model', 'checklists');
        
        $this->load->module_language('admin', 'general');
        $this->load->module_language('admin', 'checklists');
    }
    
    function index()
    {
        $data['checklists'] = $this->checklists->get_checklists();

        $this->template['page']    = "checklists/list";

        $this->system->load($this->template['page'], $data, TRUE);
    }
    
    function create()
    {
        $rules['site_name']    = "required|max_length[200]";
        $this->validation->set_rules($rules);

        $fields['site_name']            = strtolower_utf8(lang('form_checklist_name'));
        $this->validation->set_fields($fields);

        $this->validation->set_error_delimiters('', '<br />');

        if ($this->validation->run() == TRUE)
        {
            $this->checklists->create_checklist();
            $this->session->set_flashdata('message', lang('successfully_created'));

            redirect('admin/checklists', 'refresh');
        }
            
        $this->template['page']    = "checklists/create";
            
        $this->system->load($this->template['page'], null, TRUE);
    }

    function edit($id = null)
    {
        if ($id == null)
        {
            $id = $this->input->post('id');
        }
            
        $rules['site_name']    = "required|max_length[200]";
        $this->validation->set_rules($rules);
            
        $fields['site_name'] = strtolower_utf8(lang('form_checklist_name'));
        $this->validation->set_fields($fields);
            
        $this->validation->set_error_delimiters('', '<br />');
            
        $data['checklist'] = $this->checklists->get_checklist($id);
        $this->validation->site_name = $data['checklist']['site_name'];
            
        if ($this->validation->run() == TRUE)
        {
            $this->checklists->edit_checklist($id);
            $this->session->set_flashdata('message', lang('successfully_edited'));

            redirect('admin/checklists', 'refresh');
        }

        $this->template['page']    = "checklists/edit";
            
        $this->system->load($this->template['page'], $data, TRUE);
    }
    
    function development($id = null)
    {        
    
        if ($id == null)
        {
            $id = $this->input->post('id');
            
        }
        
        $rules['dl_hosting_solution']    = "numeric";
        $rules['dl_staging_website']    = "numeric";
        $rules['dl_holding_page']        = "numeric";
        $rules['dl_confirm_change']     = "required";
        $this->validation->set_rules($rules);
        
        $fields['dl_hosting_solution']     = strtolower_utf8(lang('form_checklist_dl_hosting_solution'));
        $fields['dl_staging_website']     = strtolower_utf8(lang('form_checklist_dl_staging_website'));
        $fields['dl_holding_page']         = strtolower_utf8(lang('form_checklist_dl_holding_page'));
        $fields['dl_confirm_change']     = 'dl_confirm_change';
        $this->validation->set_fields($fields);
        
        $this->validation->set_error_delimiters('', '<br />');

        $data['checklist'] = $this->checklists->get_checklist($id);
        $this->validation->dl_hosting_solution     = $this->validation->dl_hosting_solution    = $data['checklist']['dl_hosting_solution'];
        $this->validation->dl_staging_website     = $this->validation->dl_staging_website      = $data['checklist']['dl_staging_website'];
        $this->validation->dl_holder_page         = $this->validation->dl_holder_page          = $data['checklist']['dl_holder_page'];
            
        if ($this->validation->run() == FALSE)
        {
            $this->checklists->update_checklist($id);
            $this->session->set_flashdata('message', 'Please select "Confirm Changes".');
        }
            
        if ($this->validation->run() == TRUE)
        {
            $this->checklists->update_checklist($id);
            $this->session->set_flashdata('message', 'Development Cycle - Check List has successfully been updated.');

            redirect('admin/checklists', 'refresh');
        }
        
        $this->template['page']    = "checklists/development";
            
        $this->system->load($this->template['page'], null, TRUE);
    }
    
    function delete($id)
    {
        $this->checklists->delete_checklist($id);
        $this->session->set_flashdata('message', 'You have successfully deleted this Check List');

        redirect('admin/checklists', 'refresh');
    }
    
}
#2

[eluser]Sebish[/eluser]
Model:
Code:
&lt;?php

class Checklists_model extends Model
{
    function Checklists_model()
    {
        parent::Model();
        
        $this->checklists_table = 'checklists';    
    }
    
    function get_checklists()
    {
        $this->db->select('id, site_name, date_entered');
            
        $query = $this->db->get($this->checklists_table);
            
        if ($query->num_rows() > 0)
        {
            return $query->result_array();
        }
    }
    
    function get_checklist($id)
    {
        $this->db->select('id, site_name, date_entered, dl_hosting_solution, dl_staging_website, dl_holder_page');
        $this->db->where('id', $id);
            
        $query = $this->db->get($this->checklists_table, 1);
            
        if ($query->num_rows() > 0)
        {
            return $query->row_array();
        }
    }

    function create_checklist()
    {
        $data = array
                    (
                        'site_name' => $this->input->post('site_name'),
                        'date_entered' => date("Y-m-d"),
                    );

        $this->db->insert($this->checklists_table, $data);
    }

    function edit_checklist()
    {
        $data = array
                    (
                        'site_name' => $this->input->post('site_name'),
                    );

        $this->db->where('id', $this->input->post('id'));
        $this->db->update($this->checklists_table, $data);
    }

    function update_checklist()
    {
        $dl_hosting_solution     = ($this->input->post('dl_hosting_solution') == 1) ? '1' : '0';
        $dl_staging_website     = ($this->input->post('dl_staging_website') == 1) ? '1' : '0';
        $dl_holder_page         = ($this->input->post('dl_holder_page') == 1) ? '1' : '0';
        
        $data = array
                    (
                        'dl_hosting_solution'     => $dl_hosting_solution,
                        'dl_staging_website'     => $dl_staging_website,
                        'dl_holder_page'         => $dl_holder_page
                    );
        
        $this->db->where('id', $this->input->post('id'));
        $this->db->update($this->checklists_table, $data);
    }

    function delete_checklist($id)
    {
        $this->db->where('id', $id);
        $this->db->delete($this->checklists_table);
    }
    
}

View:
Code:
<div class="post">
        <div class="post_title">
            <h1>Development Cycle</h1>
        </div>
        <div class="post_body">
            <p>Manage the development cycle Check List.</p>
                
            &lt;? if ($this->session->flashdata('message')): ?&gt;
                <div class="message">
                &lt;?=$this->session->flashdata('message');?&gt;
                </div>
            &lt;? endif; ?&gt;
      
                <table width="100%">
                <tr>
                     <td colspan="2">
                         <fieldset id="main">
                             <legend>Update Development Check List</legend>
                             <table>
                                 <tr>
                                     &lt;?=form_hidden('id', $checklist['site_name']) ?&gt;
                                    <td width="750px">Is the hosting solution setup?</td>
                                     <td>&lt;?=form_checkbox('dl_hosting_solution', 0, $this->validation->dl_hosting_solution); ?&gt;</td>
                                 </tr>
                                <tr>
                                    <td width="750px">Is the staging website setup?</td>
                                     <td>&lt;?=form_checkbox('dl_staging_website', 0, $this->validation->dl_staging_website); ?&gt;</td>
                                 </tr>
                                <tr>
                                    <td width="750px">Is there a holder page inplace?</td>
                                     <td>&lt;?=form_checkbox('dl_holder_page', 0, $this->validation->dl_holder_page); ?&gt;</td>
                                 </tr>
                                <tr>
                                    <td><br /></td>
                                </tr>
                                <tr>
                                    <td width="750px">Confirm Changes?</td>
                                    <td>&lt;input type="checkbox" name="dl_confirm_change" value="0" /&gt;&lt;/td>
                                </tr>
                             </table>
                         </fieldset>
                     </td>
                </tr>
                <tr>
                    <td colspan="2">
                        &lt;?=form_hidden('id', $checklist['id']) ?&gt;
                        &lt;input type="submit" name="submit" value="&lt;?=lang('button_updatesave');?&gt;" class="styled" /&gt;
                        &lt;?=form_close();?&gt;
                    </td>
                </tr>
                </table>
        </div>
</div>
#3

[eluser]Sebish[/eluser]
Unfortunately, I haven't gotten any further.. I did realise that when click the update link I have created it takes you to "/admin/checklists/update/4" which is what I want it to do because it knows that the $id of the checklist I am editing is 4, however when I hit the "Update and Save" button without putting in an valid input it redirects me to "/admin/checklists/update" so it is losing the $id variable..

I tried to do:

Code:
if ($this->validation->run() == FALSE)
        {
            $this->checklists->update_checklist($id);
            $this->session->set_flashdata('message', 'Please select "Confirm Changes".');
            redirect('admin/checklists/updates'.$id, 'refresh');
        }

But it continually refreshes the page over and over... Instead of just once?
#4

[eluser]Sebish[/eluser]
I gave up trying to use check boxes and have decided using drop downs was easier.. and it was!

Promblem Solved Smile




Theme © iAndrew 2016 - Forum software by © MyBB