Welcome Guest, Not a member yet? Register   Sign In
Modular Separation - PHP5 (Modules)

[eluser]wiredesignz[/eluser]
Try with the module name also.
Code:
$this->load->view('sample/sample/some_view');

[eluser]Keat Liang[/eluser]
[quote author="wiredesignz" date="1300378455"]Try with the module name also.
Code:
$this->load->view('sample/sample/some_view');
[/quote]

oh that solve the problem. thanks a lot !

[eluser]Noor[/eluser]
Why Modules::run() doesn't working.

Here is my code
modules/home/controller/home.php
Code:
class Home extends MX_Controller {

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

    function index()
    {
        $this->load->view('home_view');
    }
}
and my view
Code:
<h1>Welcome to CodeIgniter!</h1>

&lt;?php echo Modules::run('home/test'); ?&gt;

<p>The page you are looking at is being generated dynamically by CodeIgniter.</p>

<p><br />Page rendered in {elapsed_time} seconds</p>
modules/home/controllers/test.php
Code:
class Test extends MX_Controller {

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

    function index()
    {
        echo 'something';
    }
}

and in the log file I get this error

ERROR - 2011-03-31 08:22:16 --&gt; Module controller failed to run: home/test

Help please

[eluser]wiredesignz[/eluser]
Your code is attempting to run the home controller test method. Try:
Code:
&lt;?php echo Modules::run('home/test/index'); ?&gt;

[eluser]Noor[/eluser]
[quote author="wiredesignz" date="1301553424"]Your code is attempting to run the home controller test method. Try:
Code:
&lt;?php echo Modules::run('home/test/index'); ?&gt;
[/quote]

Thanks, it's working now.
But, should I always type method name? including index method?

[eluser]Noor[/eluser]
I can not run controller with same name even though the module is different.
modules/events/controllers/latest.php
Code:
class Latest extends MX_Controller {

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

    function index()
    {
        echo 'several latest events';
    }
}
modules/news/controllers/latest.php
Code:
class Latest extends MX_Controller {

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

    function index()
    {
        echo 'several latest news';
    }
}
in the home_view.php I echo something like this
Code:
&lt;?php echo Modules::run('news/latest/index'); ?&gt;
<br />
&lt;?php echo Modules::run('events/latest/index'); ?&gt;
and it's output :
several latest news
several latest news

Why?

[eluser]wiredesignz[/eluser]
Why?, Because PHP does not allow you to load two classes with the same class declaration.

[eluser]Element 80[/eluser]
Is there currently any built-in method with the system to return a list of available modules?

I'm trying to figure out a way to create a sort of user-side pick-and-choose module manager, so that if I have a module for an RSS feed and a module for a mailing list, user A can opt for the RSS, user B can opt for the mailing list, and user C can go with both, but I need to know that the modules exist first to give them the choice.

I also want to make sure I'm not misusing this - "core" Controller, Model and View files for my system can/should still be run from the original application/____ folders and not application/modules/[so forth], right? I assumed this was the case, though the example on the wiki made this a little unclear.

[eluser]theprodigy[/eluser]
Quote:Is there currently any built-in method with the system to return a list of available modules?

I’m trying to figure out a way to create a sort of user-side pick-and-choose module manager, so that if I have a module for an RSS feed and a module for a mailing list, user A can opt for the RSS, user B can opt for the mailing list, and user C can go with both, but I need to know that the modules exist first to give them the choice.
The way I've handled this before was to keep track of everything in the database. You can build a "modules" table, with columns for name, folder_name, and active.

The difference between name and folder_name are:
Name: Human readable
Folder_name: the actual module folder name

This is so you can give your users options for 'RSS' and "Maillist", but name your modules 'rssfeed' and 'mail_list'.

The active column is a boolean field, so you can turn access to your modules on and off.

If you don't want to go the database route, the only other options I can think of is to do a scandir of the modules directory, then loop through the returned array using is_dir to make sure the current element is a directory, and not a file (make sure you also check for '.' and '..').

[eluser]Element 80[/eluser]
That's essentially what I want to do, but I need to know the plugin exists before it can be added to the database. Preferably, I'd like to be able to make adding modules in as simple as dropping the module into the directory and running an "Update modules" method. It sounds like the best way to do this would be the scandir method you outlined?




Theme © iAndrew 2016 - Forum software by © MyBB