Part of the EllisLab Network
x
 
Create New Page
 View Previous Changes    ( Last updated by Daniel Romero )

Hot Scaffolding

Develop a simple scaffolding for CRUD operations on tables.
It works this way:
Suppose you want to edit a master table:

/*
-----
users
----
id
category_id
name

---
*/ 

and want that your crud appears related to:

/*
----
category
----
id
name
*/ 

then this library is sufficient that you create a controller and configured as you want to see your crud.

could be:

Example class users


/system/controllers/users.php

<?php

class users extends Controller {

    
public function __construct() 
    
{
        parent
::Controller();
        
        
$param = array('baseclass'     =>__CLASS__,
                
'table'        =>'users',
                
'slaves'=>array(
          array(
'table'=>
                    array(
                
'name'        =>'category',
                
'caption'    =>'name'    ,
                
'id'        =>'id'    ,
                
'join'        =>'category_id'
                
)
            )
            ),
                
'hidden'=>array('id'),
                 
'rename'=>array(
                        
'User Category'=>'category_id',
                                                
'User Name'    =>'name'
                         
)
                       );
        
        
$this->load->library('libscaffolding',$param);
    
}
    

    
function index()
    
{
        
echo "<p>".$this->libscaffolding->newlink()."</p>";
        echo 
"<p>".$this->libscaffolding->all()."</p>";
    
}
    
    
public function edit($id)
    
{
        
echo "<p>".$this->libscaffolding->edit($id)."</p>";
    
}
    
    
public function view($id)
    
{
        
echo "<p>".$this->libscaffolding->view($id)."</p>";
    
}
        
    
public function delete($id)
    
{
        $this
->libscaffolding->_delete($id);
    
}
    
    
public function update($id)
    
{
        $this
->libscaffolding->_update($id,$_POST);//do better
    
}
    
    
public function add()
    
{
        
echo "<p>".$this->libscaffolding->add()."</p>";
    
}
    
    
public function insert()
    
{
        $this
->libscaffolding->_insert($_POST);//do better
    
}

}
?> 


clever! crud you already have a warm relationship with which you can customize to your liking.


to install this feature you must:
install the following file:

/system/libraries/libscaffolding.php

You must install this model
/system/models/advanced.php

<?php

class advanced extends Model 
{
    
public function __construct() 
    

        parent
::Model();
    
}
    
    
public function get($tabla
    
{   
         
return $this->db->get($tabla);
    
}
    
    
public function query($string)
    
{
        
return $this->db->query($string);
    
}
    
    
public function delete($array
    
{   
         $this
->db->delete($array['table'], array($array['field'=> $array['value'])); 
    
}
    
    
public function update($array
    
{   
         $this
->db->where($array['field']$array['id']);
        
$this->db->update($array['table']$array['data']); 
    
}
    
    
public function insert($array){
        
        $this
->db->insert($array['table']$array['data']);     
    
}
    
    
public function max($table,$field)
    
{
        $max 
="";
        
        
$this->db->select_max($field);
        
$rs =$this->db->get($table);
        
        foreach(
$rs->result_array() as $row)
        
{
            $max 
$row[$field];
        
}
        
        
return $max;
    
}
    
}
?> 

presto, the library has more functions to better use, you can fit your needs
bye!