Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- class Projects_model extends Model
- {
- private $_tbl = 'projects';
- .......
- // This works for my regular update
- public function updateProject( $id, $project )
- {
- $this->db->where( 'id', $id );
- $this->db->update( $this->_tbl, $project );
- }
- // Entry point
- public function addMainFileUrls()
- {
- $inputs = $this->cleanMainFileInputs();
- $id = array_shift( $inputs );
- $this->updateProject( $id, $inputs );
- }
- // Cleans up posted info before passing back to addMainFileUrls
- private function cleanMainFileInputs()
- {
- $inputs = array( 'project_id' => 'id',
- 'plans_file' => 'plans_url',
- 'specs_file' => 'specs_url' );
- $cleanUrls = array();
- foreach ($inputs as $key => $newKey) {
- $cleanUrls[$newKey] = $this->input->post($key);
- }
- return $cleanUrls;
- }
- }
- <?php
- class Projects extends Controller {
- ......
- public function files()
- {
- $this->projects->addMainFileUrls();
- redirect('/projects');
- }
- ......
- }
- ------------------------------------------------------
- var_dump of info going to Projects_model::updateProject()
- var_dump of $id = string(1) "2"
- var_dump of $inputs = array(2) {
- ["plans_url"]=>
- string(10) "A-3.07.pdf"
- ["specs_url"]=>
- string(10) "A-4.04.pdf"
- }
- -----------------------------------------------------
- Updated row in the database:
- plans_url = A-3.07.pdf
- specs_url = 0
Add Comment
Please, Sign In to add comment