SitePoint Sponsor

User Tag List

Page 3 of 3 FirstFirst 123
Results 51 to 61 of 61
  1. #51
    SitePoint Addict
    Join Date
    Sep 2006
    Posts
    232
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    It's a clever way of doing it, because at the moment, and just like you said, I'm adding another routing rule. Do you know how a colon is interpreted by a search engine?

    I'm guessing that in your system you can also simulate that HTTP request within the parent module right? Something like this:

    Code:
    $this->getModule('child_module', array('action', 'param1', 'param2'));

  2. #52
    PHP/Rails Developer Czaries's Avatar
    Join Date
    May 2004
    Location
    Central USA
    Posts
    806
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I have a way to do something like that, though it's not near as refined as your idea. With my current setup, I basically have to call the front controller again with a different request object into which I inject custom parameters. It's a bit messy in current form, though I suppose all that could be stuffed in a nice function like you have outlined to make it appear elegant .

    As for how search engines interpret the colon - I have no idea. I have seen several colons and semicolons used in URLs though, so I would just assume it would ignore them - though I could be wrong. The specific application in question is all a big admin backend, login required, etc. so it's not an issue I currently have to deal with. Should it become a problem in the future, it's easy to change.

  3. #53
    SitePoint Addict
    Join Date
    Sep 2006
    Posts
    232
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks Czaires, I appreciate your time.

    I'm now in the process of adding a unit test framework to the system, and I'm adding it as a module. For this to work, I had to change the way the router maps to methods. Before, an action was mapped to a method inside the front-end action controller of the module. Now, the router can also map to classes. Here's an example:

    Code:
    modules/
        contact-us/
            actions/
                IndexAction.php
                TestAction.php
                AddCommentAction.php
            controllers/
                ContactUs.php
                ContactUsBackend.php
                ContactUsAjax.php
                ContactUsApi.php
            models/
                ContactUsModel.php
            public/
            setup/
                ContactUsSetup.php
            views/
                index.html
    After carefully studying different options to implement a plug-in architecture inside a module, I realised that an action class itself can be considered as a plug-in, and can be added to a module independently of what the module does. The plug-in can optionally inherit the interface of the module or run as an independent object inside the module.

    S, if you request this module:

    Code:
    http://www.example.com/contact-us/test
    The router will try to map the action "test" to a method inside the ContactUs action controller, then if it can't find it, it will try to map the action to a file in the actions/ directory.

    So, for example, if I write a module called blog (how original) where you don't have the option to add comments, you can write a plug-in called AddCommentAction, and drop it inside the actions/ directory. If for some reason, your plug-in needs to access the module's interface (it might need to), it can inherit it from the action controller.

    So, how does that sound? Am I missing something, would you do it differently?

    Any idea is more than welcome, thanks.

  4. #54
    PHP/Rails Developer Czaries's Avatar
    Join Date
    May 2004
    Location
    Central USA
    Posts
    806
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    That sounds like a good idea to me - There are some developers who are used to creating a new class for every action (a la Zend Framework), so that would allow the framework to serve their needs as well. It would also allow you to break up the component/module into smaller pieces if it ever grew too large to manage as a single class file with a bunch of functions in it.

  5. #55
    SitePoint Enthusiast
    Join Date
    Aug 2007
    Posts
    92
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I have a quick question regarding modular structure. Say you do something like Zend's modular structure and have:
    Code:
    module
      controllers
      models
      views
    What do you do when you need to use a certain model in more than one module? Say you have a User model, for instance, which is used by many different modules. Where do you put it?

  6. #56
    SitePoint Addict
    Join Date
    Sep 2006
    Posts
    232
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I think it's better if you put commonly used code into libraries. The idea is to reduce intermodule dependencies. A module which calls methods in many different modules will be more difficult to maintain than a module which only calls methods in a few different modules.

    For example:

    Code:
    lib/
        Controller/
        User/
            Type/
                Frontend.php
            Abstract.php
    modules/
        auth/
        profile/
        news/
    What do you do when you need to use a certain model in more than one module?
    You get an instance of the object you want to use:

    PHP Code:
    $this->getModel('profile')->method() 

  7. #57
    SitePoint Member
    Join Date
    Oct 2007
    Posts
    22
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Angry where to store forms?

    when i first read this thread i decided to build my own CMS system, so I end up with this:
    Code:
    /img
    /lib
    /modules
        /admin
            /controllers
            /models
            /views
                admin-login.html
                admin-home.html
        /news
            /controllers
            /models
            /views
    .
    .
    /static
        /css
        /js
    index.php
    config.inc.php
    i used smarty for templating engine (you can pass array of dirs to smarty at init) and all my template files have module name as prefix so i don't get duplicate entries and have caching problems and still be able to include page from one module into another.

    next thing i want to implement are textpattern-like forms. for those of you who are not familiar wit TXP forms are small and generic pieces of code that you include in your pages.

    translated to smarty terms:

    admin-home.html
    Code:
    .
    .
    <body>
    
    <div id="container">
        {include file="admin-header.html"}
        <div id="menu">
            <ul>
    
    .
    .
    and in admin-header you define whatever header you like.

    now we get to the real problem: where to store forms and how to name them???


    since i also want to be able to include forms from one module to another, and also user should clearly distinct form from page on server, several solutions comes to my mind

    store them into:
    - static/forms/ dir in module-form_name.html format

    -make new module/views/form subdir in module-form_name.html format
    (that might be a problem with smarty and aray of dirs, to be honest i did not test this)

    -store them in views/ dir with pages but add "form_" or some other prefix to filename

    -some other solution?


    any ideas?


  8. #58
    SitePoint Addict
    Join Date
    Sep 2006
    Posts
    232
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    It doesn't matter which template engine you use, the logic is always the same. In your case, it looks like you need to adapt smarty to your architecture instead of adapting your architecture to smarty. Check where the files are included, and add some logic there.

    Remember that a modular architecture it's not just moving files and directories around, it doesn't work like that. In your case, it will help if you have a global/ directory where you put your shared templates and files. If for some crazy reason you want to use a template located in another module, you can do $this->getView('example.html', 'module_name'). But, just like I said before, try to reduce intermodule dependencies, a module that loads templates from other modules, is more difficult to maintain.

  9. #59
    SitePoint Member
    Join Date
    Oct 2007
    Posts
    22
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    i understahd that, but my problem is more in those forms than pages them self

    for example i could have global_menu.html form
    Code:
    <ul>
      <li><a href="/main/">home</a></li>
      .
      . 
    </ul>
    that i include i many different pages and modules and style them differently via css, i think of those forms as some kind of "template constants" that are available globally and you might include them whenever or where ever you like. It seams to me as good idea and i'm just wondering what is best place to put them, and how to name them.

    hope that clears things a little bit.

    edit: after reading your post and thinking a bit, i will probably put them into modules/_shared/forms/

  10. #60
    PHP/Rails Developer Czaries's Avatar
    Join Date
    May 2004
    Location
    Central USA
    Posts
    806
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by phpimpact View Post
    Remember that a modular architecture it's not just moving files and directories around, it doesn't work like that. In your case, it will help if you have a global/ directory where you put your shared templates and files. If for some crazy reason you want to use a template located in another module, you can do $this->getView('example.html', 'module_name'). But, just like I said before, try to reduce intermodule dependencies, a module that loads templates from other modules, is more difficult to maintain.
    Dependencies on items in other modules/components is one area I ran into pretty quickly with the complex application I am currently creating. I ended up having to create an additional parameter to many of the common functions to specify the module the item was in. If there was none given (defaults to NULL), the module is determined by naming conventions, or the current module in use is assumed. I also have a set of common directories in a specific subfolder that store things like the global page layouts, common images available to all modules, etc.

    My setup seems to work very similar to yours, phpimpact - I use:
    PHP Code:
    // To get a specific controller
    $this->locator->getController('News'); // Automatically looks in 'news' module (naming convention)

    // To get a specific model
    $this->locator->getModel('Users'); // Automatically looks in 'users' module (naming convention)

    // To get a common library class
    $this->locator->get('FileUpload'); // Automatically looks in global library 
    And then all of these functions have the optional second parameter to specify the module/component if you need to be more specific:
    PHP Code:
    $this->locator->get('BetterFileUpload''files'); // Looks in 'files' module library folder

    // Override naming conventions by using second optional parameter
    $this->locator->getModel('Users''customers'); // Looks in 'customers' module (overriding naming convention or looking in 'users' module) 

  11. #61
    SitePoint Member
    Join Date
    Oct 2005
    Posts
    3
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi Ya all,

    My approach to having a modular seperation and CMS is very similar. I use the following directory structure:

    Code HTML4Strict:
    /application folder
        /controllers
        /models
        /views
        /modules
            /news
            /controllers
            /models
            /views 
                 /admin
                 /public
            /languages
            /config

    I have taken the time to write my own framework which is in fact very extensible. I us a base class from which all classes in inherit

    Then i have my base controller class which has some very handy functions for loading controllers and models.

    My controller load function is something like this:
    Code PHP:
    function load_controller($p_sControllerName, $p_sModule = '') {
        if (!empty($p_sModule)) {
             require_once(cAPP.'/modules/'.$p_sModule.'/controllers/'.$p_sControllerName);
             $this->controller = & new $p_sControllerName;
        } else {
             require_once(cAPP.'/controllers/'.$p_sControllerName);
             $this->controller = & new $p_sControllerName;
        }
    }

    This is just some basic code from my framework controller class but it will highlight the principles. I have similar functions for loading models, config and language files.

    This makes it possible to load a model from any location. I just call my function from within my controller like this:
    Code PHP:
    $this->load_model('user');


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
  •