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
Reply
 
LinkBack Thread Tools Search this Thread Display Modes
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
Old 11-12-2012, 07:47 AM   #2 (permalink)
The Contributor
 
Join Date: Oct 2012
Posts: 46
Thanks: 0
ww628815 is on a distinguished road
Default

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.
ww628815 is offline  
Reply With Quote
Reply



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 07:44 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