TalkPHP

TalkPHP (http://www.talkphp.com/forums.php)
-   Advanced PHP Programming (http://www.talkphp.com/advanced-php-programming/)
-   -   Help with Controllers (http://www.talkphp.com/advanced-php-programming/4050-help-controllers.html)

triumvirat 03-17-2009 06:57 PM

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 *!*

ww628815 11-12-2012 07:47 AM

The market is flooded with jeans manufacturers with no brand name.Cheap True Religion Jeans Jeans is better purchased from authorized dealers or manufacturers.

There many places where the local jeans will be given the designer jeans tag and sold with the price of the designer jeans or certain areas you may get it at lesser price.True Religion Mens Flare is generally wrong plus the fabric quality will vary from an original designer jeans. Designer Jeans provides you with the chance to carry your attitude with it.


All times are GMT. The time now is 07:04 AM.

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0