TalkPHP
 
 
Account Login
Latest Articles
» The basic usage of PHPTAL, a XML/XHTML template library for PHP
» Vulnerable methods and the areas they are commonly trusted in.
» Simple way to protect a form from bot
» The Basics On: How Session Stealing Works
» How to keep your forms from double posting data
IRC Channel
IRC Speech Bubble Join the friendly bunch on IRC...
(#TalkPHP on Freenode)

...Also available via a web interface.

See this thread for information on the TalkPHP Free Hugs Initiative™. Subject to availability.
Associates
Associates
CSS Tutorials
 
 
LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
Old 03-17-2009, 06:57 PM   #1 (permalink)
The Wanderer
 
triumvirat's Avatar
 
Join Date: Dec 2008
Location: Russia, Moscow
Posts: 14
Thanks: 0
triumvirat is on a distinguished road
Default Help with Controllers

Hi.

I don't understand, how true make controllers in MVC model.

My current realization (reduced):

PHP Code:
// User Controller - delete, save and edit user data
// Each method performs certain actions and generates a variable to "View", 
// which are used in the templates of specific pages.
class User_Controller
{
    
// main method. 
    // this method execute all others methods of this controller
    
public function run($method)
    {
        
// if in request exists key id_user, 
        // get user data from user_mapper class
        
if ($id $this->request->get('id_user''int'))
        {
            
$this->user $user_mapper->findById($id);
        }
        
        
$this->$method();
    }
    
    
// edit and add user in database 
    
public function edit()
    {
        
// if POST method (save or edit user data)
        
if (POST)
        {
            
$this->user $user_mapper->createObjectByArray($this->request->getData('post'));
            
            
// check errors .... 
            
$errors;
            
            if (!
$errors)
            {
                
$user_mapper->save($this->user);
                
header('Location: ....');
                exit;
            }
            
            
// set view error data as array-vars 
            
$this->view->errors $errors;
        }
        
        
// set view user data as array-vars 
        
$this->view->user $this->user->getDataAsArray();
    }
    
    
// view user data 
    
public function view()
    {
        
$this->view->user $this->user->getDataAsArray();

        
// important! here other vars go to "View"-component 
        
$this->view->other_vars $this->other_method(); // this method run mysql or other operations with systems resourse
    
}
    
    
// delete user from database
    
public function delete()
    {
        
$user_mapper->delete($this->user);
    }
    
    
// and etc...

Front Controller activate this class:

PHP Code:
$c = new User_Controller();
$c->run($method_name); 
Problem.
In method User_Controller::view() we are see this code:

PHP Code:
// important! here other vars go to "View"-component 
$this->view->other_vars $this->other_method(); // this method run mysql or other operations with systems resourse 
this code make operations, specific for page /user/view/id125.html

If i have use class and method User_Controller::view() in other Controller, then I have to running and code

PHP Code:
// important! here other vars go to "View"-component 
$this->view->other_vars $this->other_method(); // this method run mysql or other operations with systems resourse 
but this code is run I do not need.

I don `t know, how to make
triumvirat is offline  
Reply With Quote
 



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


All times are GMT. The time now is 01:00 AM.

 
     

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0
Inactive Reminders By Icora Web Design