Scaffolding Class Reference

List of all members.


Public Member Functions

 Scaffolding ($db_table)
 add ()
 "Add" Page
 insert ()
 Insert the data.
 view ()
 "View" Page
 edit ()
 "Edit" Page
 update ()
 Update.
 delete ()
 Delete Confirmation.
 do_delete ()
 Delete.

Public Attributes

 $CI
 $current_table
 $base_url = ''
 $lang = array()

Detailed Description

Definition at line 28 of file Scaffolding.php.


Member Function Documentation

Scaffolding::add (  ) 

"Add" Page

Shows a form representing the currently selected DB so that data can be inserted

public

Returns:
string the HTML "add" page

Definition at line 97 of file Scaffolding.php.

00098         {       
00099                 $data = array(
00100                                                 'title' =>  ( ! isset($this->lang['scaff_add'])) ? 'Add Data' : $this->lang['scaff_add'],
00101                                                 'fields' => $this->CI->db->field_data($this->current_table),
00102                                                 'action' => $this->base_uri.'/insert'
00103                                         );
00104         
00105                 $this->CI->load->view('add', $data);
00106         }

Scaffolding::delete (  ) 

Delete Confirmation.

public

Returns:
string the HTML "delete confirm" page

Definition at line 246 of file Scaffolding.php.

00247         {
00248                 if ( ! isset($this->lang['scaff_del_confirm']))
00249                 {
00250                         $message = 'Are you sure you want to delete the following row: '.$this->CI->uri->segment(4);
00251                 }
00252                 else
00253                 {
00254                         $message = $this->lang['scaff_del_confirm'].' '.$this->CI->uri->segment(4);
00255                 }
00256                 
00257                 $data = array(
00258                                                 'title'         => ( ! isset($this->lang['scaff_delete'])) ? 'Delete Data' : $this->lang['scaff_delete'],
00259                                                 'message'       => $message,
00260                                                 'no'            => anchor(array($this->base_uri, 'view'), ( ! isset($this->lang['scaff_no'])) ? 'No' : $this->lang['scaff_no']),
00261                                                 'yes'           => anchor(array($this->base_uri, 'do_delete', $this->CI->uri->segment(4)), ( ! isset($this->lang['scaff_yes'])) ? 'Yes' : $this->lang['scaff_yes'])
00262                                         );
00263         
00264                 $this->CI->load->view('delete', $data);
00265         }

Scaffolding::do_delete (  ) 

Delete.

public

Returns:
void redirects to the view page

Definition at line 275 of file Scaffolding.php.

00276         {               
00277                 // Fetch the primary key
00278                 $primary = $this->CI->db->primary($this->current_table);                                
00279 
00280                 // Now do the query
00281                 $this->CI->db->where($primary, $this->CI->uri->segment(4));
00282                 $this->CI->db->delete($this->current_table);
00283 
00284                 header("Refresh:0;url=".site_url(array($this->base_uri, 'view')));
00285                 exit;
00286         }

Scaffolding::edit (  ) 

"Edit" Page

Shows a form representing the currently selected DB so that data can be edited

public

Returns:
string the HTML "edit" page

Definition at line 196 of file Scaffolding.php.

References view().

00197         {
00198                 if (FALSE === ($id = $this->CI->uri->segment(4)))
00199                 {
00200                         return $this->view();
00201                 }
00202 
00203                 // Fetch the primary field name
00204                 $primary = $this->CI->db->primary($this->current_table);                                
00205 
00206                 // Run the query
00207                 $query = $this->CI->db->get_where($this->current_table, array($primary => $id));
00208 
00209                 $data = array(
00210                                                 'title' =>  ( ! isset($this->lang['scaff_edit'])) ? 'Edit Data' : $this->lang['scaff_edit'],
00211                                                 'fields'        => $query->field_data(),
00212                                                 'query'         => $query->row(),
00213                                                 'action'        => $this->base_uri.'/update/'.$this->CI->uri->segment(4)
00214                                         );
00215         
00216                 $this->CI->load->view('edit', $data);
00217         }

Here is the call graph for this function:

Scaffolding::insert (  ) 

Insert the data.

public

Returns:
void redirects to the view page

Definition at line 116 of file Scaffolding.php.

00117         {               
00118                 if ($this->CI->db->insert($this->current_table, $_POST) === FALSE)
00119                 {
00120                         $this->add();
00121                 }
00122                 else
00123                 {
00124                         redirect($this->base_uri.'/view/');
00125                 }
00126         }

Scaffolding::Scaffolding ( db_table  ) 

Set the current table name This is done when initializing scaffolding: $this->load->scaffolding('table_name')

Set the path to the "view" files We'll manually override the "view" path so that the load->view function knows where to look.

Definition at line 35 of file Scaffolding.php.

References get_instance(), and log_message().

00036         {
00037                 $this->CI =& get_instance();
00038                 
00039                 $this->CI->load->database("", FALSE, TRUE);                     
00040                 $this->CI->load->library('pagination');
00041                 
00042                 // Turn off caching
00043                 $this->CI->db->cache_off();
00044                                 
00045                 /**
00046                  * Set the current table name
00047                  * This is done when initializing scaffolding:
00048                  * $this->load->scaffolding('table_name')
00049                  *
00050                  */
00051                 $this->current_table = $db_table;
00052                 
00053                 /**
00054                  * Set the path to the "view" files
00055                  * We'll manually override the "view" path so that
00056                  * the load->view function knows where to look.
00057                  */
00058                 
00059                 $this->CI->load->_ci_view_path = BASEPATH.'scaffolding/views/';
00060 
00061                 // Set the base URL
00062                 $this->base_url = $this->CI->config->site_url().'/'.$this->CI->uri->segment(1).$this->CI->uri->slash_segment(2, 'both');
00063                 $this->base_uri = $this->CI->uri->segment(1).$this->CI->uri->slash_segment(2, 'leading');
00064 
00065                 // Set a few globals
00066                 $data = array(
00067                                                 'image_url'     => $this->CI->config->system_url().'scaffolding/images/',
00068                                                 'base_uri'  => $this->base_uri,
00069                                                 'base_url'      => $this->base_url,
00070                                                 'title'         => $this->current_table
00071                                         );
00072                 
00073                 $this->CI->load->vars($data);
00074                 
00075                 // Load the language file and create variables
00076                 $this->lang = $this->CI->load->scaffold_language('scaffolding', '', TRUE);
00077                 $this->CI->load->vars($this->lang);
00078                                 
00079                 //  Load the helper files we plan to use
00080                 $this->CI->load->helper(array('url', 'form'));
00081                 
00082                                 
00083                 log_message('debug', 'Scaffolding Class Initialized');
00084         }

Here is the call graph for this function:

Scaffolding::update (  ) 

Update.

public

Returns:
void redirects to the view page

Definition at line 227 of file Scaffolding.php.

00228         {       
00229                 // Fetch the primary key
00230                 $primary = $this->CI->db->primary($this->current_table);                                
00231 
00232                 // Now do the query
00233                 $this->CI->db->update($this->current_table, $_POST, array($primary => $this->CI->uri->segment(4)));
00234                 
00235                 redirect($this->base_uri.'/view/');
00236         }

Scaffolding::view (  ) 

"View" Page

Shows a table containing the data in the currently selected DB

public

Returns:
string the HTML "view" page

Definition at line 139 of file Scaffolding.php.

Referenced by edit().

00140         {
00141                 // Fetch the total number of DB rows
00142                 $total_rows = $this->CI->db->count_all($this->current_table);
00143                 
00144                 if ($total_rows < 1)
00145                 {
00146                         return $this->CI->load->view('no_data');
00147                 }
00148                 
00149                 // Set the query limit/offset
00150                 $per_page = 20;
00151                 $offset = $this->CI->uri->segment(4, 0);
00152                 
00153                 // Run the query
00154                 $query = $this->CI->db->get($this->current_table, $per_page, $offset);
00155 
00156                 // Now let's get the field names                                
00157                 $fields = $this->CI->db->list_fields($this->current_table);
00158                 
00159                 // We assume that the column in the first position is the primary field.
00160                 $primary = current($fields);
00161 
00162                 // Pagination!
00163                 $this->CI->pagination->initialize(
00164                                                         array(
00165                                                                         'base_url'               => $this->base_url.'/view',
00166                                                                         'total_rows'     => $total_rows,
00167                                                                         'per_page'               => $per_page,
00168                                                                         'uri_segment'    => 4,
00169                                                                         'full_tag_open'  => '<p>',
00170                                                                         'full_tag_close' => '</p>'
00171                                                                         )
00172                                                                 );      
00173 
00174                 $data = array(
00175                                                 'title' =>  ( ! isset($this->lang['scaff_view'])) ? 'View Data' : $this->lang['scaff_view'],
00176                                                 'query'         => $query,
00177                                                 'fields'        => $fields,
00178                                                 'primary'       => $primary,
00179                                                 'paginate'      => $this->CI->pagination->create_links()
00180                                         );
00181                                                 
00182                 $this->CI->load->view('view', $data);
00183         }

Here is the caller graph for this function:


Member Data Documentation

Scaffolding::$base_url = ''

Definition at line 32 of file Scaffolding.php.

Scaffolding::$CI

Definition at line 30 of file Scaffolding.php.

Scaffolding::$current_table

Definition at line 31 of file Scaffolding.php.

Scaffolding::$lang = array()

Definition at line 33 of file Scaffolding.php.


The documentation for this class was generated from the following file: