SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Addict
    Join Date
    Apr 2004
    Location
    Melbourne
    Posts
    362
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    ASP.NET style framework for PHP5

    I've noticed over the last few months that this seems to be a hotbed of discussion on template based frameworks, so I thought I'd throw a project I've been working on up into the mix. It's only in its infancy, so there is still a lot left to do, and the templating engine is rather fragile (based on regexs), and it's by no means blazingly fast (speed is one of the main things I'll be looking at improving). There are a couple of examples included, the one below and another one that has a bit of everything; modules, user-defined template based controls, and validators, which is included in the download.

    http://webpanels.sourceforge.net

    I've rewritten a project I was working on called WebPanels for PHP5, and based it around ASP.NET's code behind approach. This means that you can design a form in Visual Studio or the free ASP.NET WebMatrix editor, and it will be displayed by my framework, with controls declared in the template file imported into the Page class' namespace. A quick example;

    A template file like this,

    Code:
    <html>
    <head>
    </head>
    <body>
        <form id="SampleForm" runat="server">
            <p>
                <php-TextBox id="TextBox1" runat="server"></php-TextBox>
            </p>
            <p>
                <php-Button id="Button1" runat="server" Text="Button" OnClick="ClickButton" />
            </p>
            <p>
                <php-Label id="Label1" runat="server">Label</php-Label>
            </p>
            <!-- Insert content here -->
        </form>
    </body>
    </html>
    and a class file like

    PHP Code:
    <?php
    require_once("./WebPanels/webpanels.config.php");

    using("WebPanels.Web.UI");

    class 
    SamplePage extends Page
    {

        function 
    __construct()
        {
            
    parent::__construct("SamplePage");
            
    $this->SetTemplate("./SamplePage.html");
        }
        
        function 
    ClickButton()
        {
            
    $this->Label1->Text($this->TextBox1->Text());
        }
    }

    $page = new SamplePage();
    $page->Init();
    $page->Run();
    $page->Render();

    ?>
    produces an output like


    If you're playing around with PHP5, I'd appreciate if you could take a bit of time to look at it and give me some suggestions, or criticise me for being a fool reimplementing something that's not so great to begin with .

  2. #2
    Non-Member
    Join Date
    Jan 2004
    Location
    Planet Earth
    Posts
    1,764
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Unfortunately I'm still with version 4 for the foreseeable future, but I'd be interested in seeing how your

    PHP Code:
    using("WebPanels.Web.UI"); 
    works Is it possible for you to post it I wonder ??

  3. #3
    SitePoint Addict
    Join Date
    Apr 2004
    Location
    Melbourne
    Posts
    362
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Widow Maker
    Unfortunately I'm still with version 4 for the foreseeable future, but I'd be interested in seeing how your

    PHP Code:
    using("WebPanels.Web.UI"); 
    works Is it possible for you to post it I wonder ??
    It's quite simple really; replace all the '.' characters with path separator characters, do a quick check to make sure that you haven't already made a call to 'using' for that namespace, then simply add it to the "include_path" variable with ini_get and ini_set .

    PHP Code:
    //The base directory (note that you must include the trailing slash).
    define("WEBPANELS_PARENT""C:/Development/websites/WebPanels2/");
    define("WEBPANELS_BASE"WEBPANELS_PARENT."WebPanels/");

    //magic_quotes_gpc is horrible. Detect for it and convert if found.
    if(get_magic_quotes_gpc()) {
    $_GET array_map("stripslashes"$_GET);
    $_POST array_map("stripslashes"$_POST);
    $_COOKIES array_map("stripslashes"$_COOKIES);
    /*$_POST = array_map("stripslashes", $_POST);
    $_POST = array_map("stripslashes", $_POST);*/
    }

    function 
    using($namespace)
    {
        
    //Keeps a list of things we've already required.
        
    static $required = array();
        
        
    //Now set the include_path to that directory.
        
    if( !in_array($namespace$required)) {
            
    $required[] = $namespace;
            
    $dir WEBPANELS_PARENT.str_replace(".""/"$namespace)."";
            
            
    $cur ini_get("include_path");
            
    $cur .= ";".$dir;
            
    ini_set("include_path"$cur);
        }
    }

    function 
    __autoload($className) {
        require_once(
    $className ".php");

    One quick question while I think of it; does anyone know if the REQUEST global array is affected by magic_quotes_gpc?

  4. #4
    Non-Member
    Join Date
    Jan 2004
    Location
    Planet Earth
    Posts
    1,764
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Would think much so that $_REQUEST would be in the same boat as $_GET, $_POST et al ? Nothing special about $_REQUEST that I know of

    Have you ran some test data on it ?


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
  •