SitePoint Sponsor

User Tag List

Results 1 to 8 of 8
  1. #1
    SitePoint Member
    Join Date
    Sep 2003
    Location
    Boston
    Posts
    10
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Phrame, MappingManager, & ActionForms

    I'm being forced to move from Perl's MVC CGI::Application/ HTML::Template platform to PHP due to a server migration at a client. I've read the two Phrame articles in php|architect and was excited to continue using an MVC framework, which I did not think was possible in PHP.

    As a Perl guy, I'm used to abstruse code, but I am still lost when it comes to the manner in which ActionForms and Actions interact within Jason Sweat's Mapping Manager framework. I'm also new to PHP (but finding it relatively easy, even if I automatically type my in front of every variable declaration....)

    I have got Phrame running on both Linux and W2K, and have coded my own application to take event records from the database and display them in a web form. However, when I try to submit changes to the record, I'm getting header already sent errors. Thus, I'm curious as to how to use the ActionForm: do I need to perform some manipulation of the submitted _REQEUST and then (and only then) send it onto the Action? And once I've written the record to the database, how do I forward back to the edit view? Is there a good general example beyond the MVC Links Application, perhaps something which does not try to handle simultaneous updates to multiple records on a web page like Jason's MVC example?

    Many thanks,

    - John


  2. #2
    eschew sesquipedalians silver trophy sweatje's Avatar
    Join Date
    Jun 2003
    Location
    Iowa, USA
    Posts
    3,749
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi John, glad you liked the articles.

    The header already sent is probably due to some white space outside of the php parsed code, for example, a couple of carriage returns after the last ?> in one of the include files. One of the easiest ways to try to solve this problem is to
    a) make sure <?php is the first line of the file, and
    b) remove the last ?>

    It is optional, and can only lead to problems like the one you are experiencing

    HTH
    Jason Sweat ZCE - jsweat_php@yahoo.com
    Book: PHP Patterns
    Good Stuff: SimpleTest PHPUnit FireFox ADOdb YUI
    Detestable (adjective): software that isn't testable.

  3. #3
    SitePoint Member
    Join Date
    Sep 2003
    Location
    Boston
    Posts
    10
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Jason,

    Thanks for your lightening response. I tried removing the ?>'s, to no avail. My goal is to get this little test app running so I can work on a larger intranet project. So I've included my code below in hopes that someone else's eyes will find my bug shallow.

    When I run my app, I can display a form with data for one event record. When I submit that web form back from the browser, I get the following error:


    DISABLE_PHRAME_ERROR_HANDLING debugging mode enabled


    Warning: Cannot add header information - headers already sent by (output started at e:\php\phpdev\private\mysqlmvc\event_setup.php:111) in e:\php\phpdev\private\lib\phrame\ActionController.jes.php on line 250

    Here are the relevant lines of code....

    PHP Code:

    /// SETUP  ///////////////////////////////////////////////

    lines 107-111

    /// START SESSION
    //all classes defined, we can now load the session
    session_start();


    /// SET ERROR HANDLING
    if(defined('DISABLE_PHRAME_ERROR_HANDLING') && DISABLE_PHRAME_ERROR_HANDLING !== false
    {
        
    error_reporting(E_ALL);
    print 
    "DISABLE_PHRAME_ERROR_HANDLING debugging mode enabled<p>\n";
    }


    /// ACTION  ///////////////////////////

    class UpdateEvent extends Action
    {

        function &
    Perform(&$poActionMapping, &$poActionForm)
        {
            global 
    $gb_debug;
            
            
    $event =& new Events;

            
    // Get the Event Data for the current event_id
                    
            
    $rec['event_id']          = $poActionForm->Get('event_id');
            
    $rec['event_title']       = $poActionForm->Get('event_title');
            
    $rec['event_date_start']  = $poActionForm->Get('event_date_start');
            
    $rec['event_date_end']    = $poActionForm->Get('event_date_end');
            
            
    $update_id $event->Update($rec);
            
            if (!(
    $update_id))
            {    
                
    appl_error('Update Record failed');
                exit;
                            
            } else 
            {
            
                
    $o_action_forward =& $poActionMapping->Get('edit');
            
                
    $o_action_forward->SetPath($o_action_forward->GetPath()."&event_id=$update_id");
                return 
    $o_action_forward;
            }    
           } 
    }


    /// MAPPING  ///////////////////////////////////
    /// EventMap.php: Extends Mapping Manager

    class EventsMap extends MappingManager
    {
            
    // UPDATE    
             
    $this->_AddForm('update_event''ActionForm');        
                                
            
    $this->_AddMapping'UpdateEvent',             // Mapping Name 
                                
    'UpdateEvent',             // Class to Implement
                                
    APPL_BASE.'eventedit',     // Default Location whence called
                                
    'update_event');          // form mapping
                                
            
    $this->_AddForward'UpdateEvent',             // ActionMapping Identifier
                                
    'edit');                   // Forward Name
    }


    /// VIEW  ////////////////////////////

    class UpdateEventView extends View
    {
        
    /**
         *    template
         */
        
    var $_msTemplate DETAIL_VIEW_TEMPLATE;
        
        
    /**
         *    constructor function
         *    @return    void
         */
        
    function UpdateEventView()
        {
        }

        
    /**
         * assign data to Smarty in preperation for display
         *
         * @param    object    $poSmarty    the smarty instance
         * @return    void
         */
        
    function Prepare()
        {
        
            
    $event_id = (int)$this->_moForm->Get('event_id');
            
    $detail   = (int)$this->_moForm->Get('detail');
            
            
    $this->_moTpl->Assign(array(
                 
    'title_extra'    => 'Event Detail'
                
    ,'view'            => 'event_detail'
                
    ,'debugging'    => '1'
                 
    ,'detail'        => Events::GetDetail($event_id)
                 ,
    'event_id'     => $event_id
    #            ,'test'            => var_export(Events::GetDetail(), true),
                
    ));

            
    $this->_mbPrepared true;
        }
        

    What am I doing wrong? I have a feeling it has something to do with the way I map ActionForms to Actions, but I can't figure it out. Thanks for your help!

  4. #4
    SitePoint Member
    Join Date
    Sep 2003
    Location
    Boston
    Posts
    10
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    READ THIS FIRST!

    Hmmm... commenting out lines 107-111 in the event_setup.php file led to the app (and update) working.... duh...

    Now I'm turning to getting error reporting back working. Sorry to bother you!

    - John

  5. #5
    eschew sesquipedalians silver trophy sweatje's Avatar
    Join Date
    Jun 2003
    Location
    Iowa, USA
    Posts
    3,749
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Glad to be of help... I think

  6. #6
    SitePoint Member
    Join Date
    Sep 2003
    Location
    Boston
    Posts
    10
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Jason,

    You've been a great help, particularly with your articles and the MappingManager class. Thank you!

    I got everything working last night and am now setting out to build a complete application. Once I'm done, I'll see if I can transcribe my notes from learning Phrame into a mini how-to.

    Thanks again,

    - John

  7. #7
    Non-Member
    Join Date
    Jan 2003
    Posts
    5,748
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Mini know-how ?

    That would be great if you could ? Let the rest of us get to grips with Phrame

  8. #8
    SitePoint Enthusiast
    Join Date
    Feb 2003
    Location
    CA
    Posts
    29
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    just so you know:
    the reason you were getting that error is because of the session_start().
    that call has to be before you output anything.
    usually it is called at the very beginning of the script using sessions.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •