ExpressionEngine CMS
Open, Free, Amazing

Thread

This is an archived forum and the content is probably no longer relevant, but is provided here for posterity.

The active forums are here.

Modular Extensions - HMVC version 5.4

January 29, 2011 1:58am

Subscribe [99]
  • #166 / Nov 16, 2011 7:11am

    PhilTem

    872 posts

    I currently don’t have a solution for your problem/desire but I’m planing on developing such a feature for the ICF (IgnitedCommunityFramework) which indeed provides somehow that functionality:

    A module (just a folder inside ./application/modules, let’s call it ‘gallery’) is developed on a localhost and after successful integration and testing to the local-icf can be ported to the production site. But it will only be run and accessible via the admin-interface if the install()-method is run once to create the needed database schemes and so on and so forth.
    So basically, anything like

    $this->gallery->users_gallery()

    can only be run, if the module was installed (i.e. simply registered inside the database). I already asked in this forums if there is something like this module-installation. See http://ellislab.com/forums/viewthread/201701

    Maybe we can have some closer look at this together and drop off some code for the community. Hit me up with a PM if you’re interested so we won’t spoil this thread. Anybody else interested: Hit me up as well 😉

    But in general I’d suggest you add the basic layout-files to the template itself and then module-specific via your module (i.e. load in the controller via some library like ‘assets’ which of course ought to check for duplicate included style or js-files - actually a nice topic to do some research on, since I don’t know whether Phil’s assets-library supports this feature?!)

  • #167 / Nov 16, 2011 7:42am

    Kobus M

    54 posts

    Hi Phil,

    Thanks for your comment. I will look out for your solution.

    My requirement, however, is not to create the install script or setting the default accesses, etc., that part is already 90% complete. My huge need is to not have module files scattered all over the place, but all into a single container folder, which may or may not include CSS, scripts, images, helpers, etc.

    So, instead of having my controllers in a central controller directory, the models, in another, css files with the rest of the CSS files, etc., I would like to have one folder in the “modules” folder, e.g., “survey” which will contain all the files the module “owns”, such as images, CSS, etc.

    Thanks,

    Kobus

  • #168 / Nov 17, 2011 4:07am

    Kobus M

    54 posts

    Hi,

    In case this helps anyone with the same request that I have, I have played around with my options, and my final choice for this was to prefix admin module folders with the word ‘admin_’.

    My folder structure is thus now as follows:

    modules
    —-admin_user
    ———controllers
    ———models
    ———views
    —-admin_core
    ———controllers
    ———models
    ———views
    —-survey
    ———controllers
    ———models
    ———views
    —-user
    ———controllers
    ———models
    ———views

    Not sure if this is ideal, but it is the best solution I could currently find.

    Thanks wiredesignz for your hard work on this. In general, when people have issues they are fast to complain or ask support but slow to say thanks, and I was guilty of that myself, I apologize. Thanks for an excellent solution!

    Kobus

  • #169 / Nov 17, 2011 4:22am

    wiredesignz

    2882 posts

    ... Thanks for an excellent solution!

    You’re welcome.

  • #170 / Nov 21, 2011 3:23pm

    PhilTem

    872 posts

    Forgive me if I’m wrong but I ran into a probably rather simply and stupid error but here’s how you get to it too:

    1) Take a clean CI 2.1.0 and copy it to some folder on your server
    2) Test in browser => Everything works fine
    3) Take a clean Clone from your HMVC (actually it’s from saturday, so your commit form yesterday is not included) and copy it according to the setup rules to the CI-folder
    4) Go to browser => Everything works fine
    5) Edit ./application/config/database.php and fill in database-information
    6) Edit ./application/config/autoload.php and set $autoload[‘libraries’] = array(‘database’);
    7) Check page => Works fine
    8) Edit ./application/config/database.php and set session’s encryption key as well as ‘use_database’ to TRUE
    9) Edit ./application/config/autoload.php and set $autoload[‘libraries’] = array(‘session’);
    10) Go to browser => Everything fine
    11) Edit ./application/controllers/welcome.php and add

    public function __construct()
    {
        parent::__construct();
    }

    12) Go to browser => Everything fine
    13) Create a MY_Controller in ./application/core with the following code

    <?php (defined('BASEPATH')) OR exit('No direct script access allowed');
    
    /* load the MX_Router class */
    require APPPATH."third_party/MX/Controller.php"; // comment this line and everything works fine, too
    
    class MY_Controller extends CI_Controller {
        function __construct()
        {
            parent::__construct();
        }
    }

    14) Go to browser and get

    A PHP Error was encountered
    
    Severity: Notice
    
    Message: Undefined property: Welcome::$db
    
    Filename: libraries/Session.php
    
    Line Number: 201
    
    Fatal error: Call to a member function where() on a non-object in /var/www/htdocs/codeigniter/ci-hmvc/codeigniter/libraries/Session.php on line 201

    First I had that problem within a repo which had per-environment files for both config.php and database.php but not for autoload.php. So I thought the problem was there. But as you can see, it’s coming even with a clean CI-install.

    Maybe I got something wrong, but what’s so bad about having your welcome controller extend the CI_Controller and only place a MY_Controller file inside the core-folder which does nothing (except including the MX_Controller) but extending the CI_Controller?
    And even if you changed

    class MY_Controller extends CI_Controller {
        function __construct()
        {
            parent::__construct();
        }
    }

    to

    class MY_Controller extends MX_Controller {
        function __construct()
        {
            parent::__construct();
        }
    }

    you still get that error.

    Is this error-creation my fault?
    I know why one should use to extend the MX_Controller (for HMVC-stuff) but for this project I thought of seperating HMVC-Controllers from basic-controllers. So to say to have a MY_Controller (extending CI_Controller) for the default-controllers and a HMVC-Controller extending (MX_Controller).
    And from my point of view there’s nothing wrong about having a controller extending CI_Controller even if there is a MY_Controller, or is it? Does this interfere with the possibility to extend the core-classes?

    Checked with a CI-2.1.0-dev build: Same procedure, but no problems.

  • #171 / Nov 21, 2011 4:42pm

    wiredesignz

    2882 posts

    @PhilTem, You never need to deliberately include MX_Controller, it will be loaded by spl_autoload if a controller extends it.
    The error occurs because the core objects (database, etc) are not associated with CI_Controller if MX_Controller is loaded first

  • #172 / Nov 22, 2011 12:56am

    mtsandeep

    41 posts

    getting the same error for me too.

    <?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
    
    class  MY_Controller  extends  CI_Controller  {
    }
    class  MX_Controller  extends  MY_Controller  {
    
        public function __construct()
     {
            parent::__construct();
      if (ENVIRONMENT == 'development')
      {
       $this->load->library('console');
       $this->output->enable_profiler(true);
      } 
        }
    }

    I was using this for MY_Controller
    database class is not getting loaded. I am having some libraries and controllers in normal codeigniter application folder, I am trying to use those inside the modules and its shoing this ::$db error.

    How to fix this?

    I need to have some functions running in all modules as if we run through MY_Controller normally, I would like to use MX_Controller. how can i do this?

  • #173 / Nov 22, 2011 1:40am

    wiredesignz

    2882 posts

    @mtsandeep, Why are you creating the MX_Controller class?

    MX_Controller is already part of Modular Extensions HMVC. See “third_party/MX/Controller.php”

  • #174 / Nov 22, 2011 1:53am

    mtsandeep

    41 posts

    How to add some functions auto loading in all modules?

  • #175 / Nov 22, 2011 2:24am

    wiredesignz

    2882 posts

    How to add some functions auto loading in all modules?

    Please explain what you want with a lot more detail.

  • #176 / Nov 22, 2011 2:27am

    PhilTem

    872 posts

    @PhilTem, You never need to deliberately include MX_Controller, it will be loaded by spl_autoload if a controller extends it.
    The error occurs because the core objects (database, etc) are not associated with CI_Controller if MX_Controller is loaded first

    So I’ll just cut off the line producing me headaches - and you, too.
    But anyhow I’m curious why it’s producing an error with the latest CI-2.1.0-release but not with a CI-2.1.0-devbuild. Would be great if you explained it to me 😉 since it worked with CI <= 2.0.3 that way too producing no errors.

    And for something totally off-topic: What’s the price of a beer in your favorite bar around? Or you’re more likely to drink wine? Have seen your ‘Donate’-Button on BitBucket 😉

  • #177 / Nov 22, 2011 3:02am

    mtsandeep

    41 posts

    How to add some functions auto loading in all modules?

    Please explain what you want with a lot more detail.

    In my MY_Controller i am having a profiler loading so i can see that from all the controllers, i wanted that same thing to be from modules also. My MY_Controller code is

    <?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
    
    class  MY_Controller  extends  CI_Controller  {
        public function __construct()
     {
            parent::__construct();
      if (ENVIRONMENT == 'development')
      {
       $this->load->library('console');
       $this->output->enable_profiler(true);
       add_filter(theme_chooser_bar());
      } 
        }
    }

    I have setup a demo
    https://apps.codinglog.com/ (home page redirects to login page, extends MY_Controller) profiler is shown, right top corner icon
    https://apps.codinglog.com/admin (admin module) How to show profiler here? show profiler in all modules

    With MY_Controller i could easily show the profiler in all controllers which extends MY_Controller, Is there any way to include this with hmvc

  • #178 / Nov 22, 2011 3:17am

    wiredesignz

    2882 posts

    @PhilTem, Sorry I have no idea why it may have worked like that with CI2.0-dev. However for you to use the HMVC functionality available in MX you must extend MX_Controller rather than CI_Controller.

    @mtsandeep, The same applies for your problems. MY_Controller must extend MX_Controller if you need HMVC functionality in your application.

  • #179 / Nov 22, 2011 3:48am

    PhilTem

    872 posts

    @wiredesignz Well, I am glad to know you don’t see the error-producing code either even though you’re probably a better coder than I am 😉

    So, just to clarify things for me, I’m fine with some setup like this:

    class MY_Controller extends CI_Controller {...

    for the default-controllers that won't need to have HMVC-functionality and

    class Hmvc_controller extends MX_Controller {...

    for controllers that provide HMVC-functionality?!
    And I won't ever write anything like

    require APPPATH."third_party/MX/Controller.php";

    into any of my controller-declaration files?!

    Think I can handle that 😉

  • #180 / Nov 22, 2011 3:48am

    mtsandeep

    41 posts

    nothing happened. I changed CI_Controller to MX_Controller. The controllers in applications/controller folder works as earlier. nothing changed in the controllers inside modules, its not displaying the profiler i outputted at MY_Controller.

    Any ideas?

.(JavaScript must be enabled to view this email address)

ExpressionEngine News!

#eecms, #events, #releases