Welcome Guest, Not a member yet? Register   Sign In
parent::get();
#1

[eluser]cerberus478[/eluser]
I'm busy doing a tutorial and I ended up stuck on a section that isn't working and that I don't understand. What I'm suppose to do is to give my pages a parent id.
By selecting the id and title where parent_id = 0 and then it fetches the pages and stores them

This is my pages_model
Code:
function get_no_parents(){
  //Fetches the pages without parents
      
  $this->db->select('id, title');
  $this->db->where('parent_id', 0);
  $pages = parent::get();
  
  //Returns key => value pair array
  $array = array(0 => 'No parent');
  if (count($pages)){
   foreach($pages as $page){
    $array[$page->id] = $page->title;
   }
  }
}

My create view
Code:
<?php
    

    echo validation_errors("<p  red;'>", "</p>");
    
    echo form_open('pages/submit/'.$update_id);
?&gt;
<table width="900" cellpadding="8" cellspacing="0" border="1">
<tr>
  <td>
   &lt;?php
    //create a drop down form with an array called pages_no_parents
    echo form_dropdown('parent_id', $pages_no_parents, $this->input->post('parent_id') ? $this->input->post('parent_id') : $page->parent_id);
   ?&gt;
  </td>
</tr>
    <tr>
        <td> Title:
            &lt;?php
                $data = array(
                    'name' => 'title',
                    'id' => 'title',
                    'value' => $title,
                    'maxlength' => '230',
                    'size' => '50',
                    'style' => 'width: 320px;',
                );
                
                echo form_input($data);
            ?&gt;
        </td>
        <td> Meta Title:
            &lt;?php
                $data = array(
                    'name' => 'meta_title',
                    'id' => 'meta_title',
                    'value' => $meta_title,
                    'maxlength' => '230',
                    'size' => '50',
                    'style' => 'width: 320px;',
                );
                
                echo form_input($data);
            ?&gt;
        </td>
    </tr>
    
    <tr>
        <td colspan="2"> Keywords:
            &lt;?php
                $data = array(
                    'name' => 'keywords',
                    'id' => 'keywords',
                    'value' => $keywords,
                    'maxlength' => '230',
                    'size' => '50',
                    'style' => 'width: 800px;',
                );
                
                echo form_input($data);
            ?&gt;
        </td>
    </tr>
    
     <tr>
        <td colspan="2"> Meta Description:
            &lt;?php
                $data = array(
                    'name' => 'meta_description',
                    'id' => 'meta_description',
                    'value' => $meta_description,
                    'maxlength' => '230',
                    'size' => '50',
                    'style' => 'width: 700px;',
                );
                
                echo form_input($data);
            ?&gt;
        </td>
    </tr>
  
    <tr>
    
        <td colspan="2" id="content"> Content:
            &lt;?php
                $data = array(
                    'name' => 'content',
                    'id' => 'content',
                    'value' => $content,
                    'rows' => '30',
                    'cols' => '50',
                    'style' => 'width: 750px;',
                );
                
                echo form_textarea($data);
            ?&gt;
        </td>
    </tr>
    
    <tr>
        <td colspan="2" align="center">
            &lt;?php
                echo form_submit('submit', 'Submit');
            ?&gt;
        </td>
    </tr>
</table>

&lt;?php
    echo form_close();

and my pages controller
Code:
function create(){

        
        $update_id = $this->uri->segment(3);
        $submit = $this->input->post('submit', TRUE);
        
        if($submit=="Submit"){
            //person has submitted the form
            $data = $this->get_data_from_post();
        } else {
            if(is_numeric($update_id)){
                $data = $this->get_data_from_db($update_id);
            }
        }
        
        if(!isset($data)){
            $data = $this->get_data_from_post();
        }
  
  //Pages for dropdown
  $data['pages_no_parents'] = $this->pages_model->get_no_parents();
  echo print_r($data['pages_no_parents']);
  
        
        $data['update_id'] = $update_id;
        
        $data['view_file'] = "create";
        $this->load->module('template');
        $this->template->admin($data);
    }

**UPDATE: I found out what it was




Theme © iAndrew 2016 - Forum software by © MyBB