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 - Version 4.3

March 03, 2008 6:10pm

Subscribe [48]
  • #466 / Jun 07, 2008 7:27am

    gerben

    75 posts

    Thanks, I hadn’t thought of that, but it works fine 😊

  • #467 / Jun 07, 2008 10:55am

    yusufdestina

    16 posts

    I can’t figure this out.
    I have a module “news” located in application/modules/news/controllers/news.php

    <?php if (!defined('BASEPATH')) exit('No direct script access allowed');
    
    class News extends Controller
    {
        function News()
        {
            parent::Controller();
            $this->load->model('news_model');
        $this->load->language('news');
        }
        
        function index()
        {
        $data['news'] = $this->news_model->get_news('nl');
            return $this->load->view('news_view', $data);
        }
        
        function item($id)
        {
            $min = $this->news_model->get_minimum();
            $max = $this->news_model->get_maximum();
            if ($id > $min->id){
                   $previous = $this->news_model->get_previous($id);
                   $data['prev_news_id'] = $previous->id;
               }else{
                   $data['prev_news_id']  = false;
               }
               if ($id < $max->id){
                   $next = $this->news_model->get_next($id);
                   $data['next_news_id'] = $next->id;
               }else{
                   $data['next_news_id'] = false;
               }
            
            $data['content'] = $this->news_model->get_news_item($id, 'nl');
            return $this->load->view('item_view', $data, TRUE);
        }
    }

    From a Controller inside application/controllers/newsitem.php
    I trie to fetch the data from the item method in my module.

    <?php
    class Newsitem extends Controller{
        
        function Newsitem(){
            parent::Controller();
            $this->lang->load('site', 'nl_BE');
            $data['pageTitle'] = "dummy title.";
            $this->load->vars($data);
        }
        
        function index()
        {
            $id = (int) $this->uri->segment(2,0);
            
            $data['content'] = modules::run('news', $id, 'item',FALSE);
            $data['contentForLayout'] = $this->load->view('themes/'.$this->config->item('theme', 'theme').'/pages/default',$data,TRUE);
            $this->load->view('themes/'.$this->config->item('theme','theme').'/layout/default', $data);
        }    
    }
    ?>

    When Executing this I get 404 page not found
    So i set my route in routes.php
    to

    $route['newsitem/:num'] = "newsitem";

    Then I get this error:

    Call to undefined method News_model::get_news() in C:\server\www\ci\system\application\modules\news\controllers\news.php on line 20

  • #468 / Jun 07, 2008 11:41am

    wiredesignz

    2882 posts

    what URL is causing the 404?, have you tried without the modules:run call to the module controller?

    You can also try $this->load->module(‘news’) and then call it’s item() method: $this->news->item($id);

    EDIT:
    Thanks for the update, Yes but your route should also pass the id segment:

    route[‘newsitem/:num’] = ‘newsitem/$1’;

  • #469 / Jun 10, 2008 5:39am

    yusufdestina

    16 posts

    my bad… I had a front controller with the same name as my module. I changed that, and everything is working well now. tnx for ur time.

  • #470 / Jun 10, 2008 5:58am

    wiredesignz

    2882 posts

    Glad you got it working 😉

  • #471 / Jul 08, 2008 7:56am

    pengekcs

    2 posts

    My modules (kcs_captcha_module - available on wiki, just updated it) stopped working when I upgraded from 4.1.11 to 4.1.20. This is the second time something that breaks the whole thing happens. As it’s a community project - and I do like it in some ways - I have tracked down the bug to my module ending in a return ‘some value’; whilst the modules::run method has been changed to do output buffering between the versions. So I just needed to echo ‘some value’ instead of returning it.

    Would have been good if you mentioned it somewhere on the forums, wiredezigz 😉 - FYI I update your HMVC wiki to reflect this.

    - Also, would not it be possible to use MY_Controller.php instead of completely replacing the CI original with a Controller.php ? In case of a session module it is fine, but your code seems to be doing some ‘magic’ in there…

    - While I am also here, is it possible / recommended at all to have multiple controllers in a module? Right now afaik if I have a module named: ‘something’, then it will look for this at:
    /modules/something/controllers/something.php

    And I can access it from a view or controller by calling modules::run(‘something’, ‘some value passed’, ‘function_name’);

    If I have a /modules/something/controllers/an_other_thing.php - How can I call / run it?

    - What is the autoload functionality you mentioned a few pages before that you’ve added doing? How can we use it?

    In the end it would be good if CI would build in a similar functionality that your code provides. I find it really easy to just drop in some modules that I made and have them working promptly 😉

    So keep up the good work! (but also, please, please keep the wiki updated if you have a chance - without that it makes some of us frustrated and wasting time trying to figure out what to do, and how)

  • #472 / Jul 08, 2008 9:23pm

    wiredesignz

    2882 posts

    Thanks for updating the wiki, this being a community project means your contribution is welcome too.

    Yes it is possible to use more than one controller per module, simply use the module name as a prefix segment.

    ie: modules::run(‘module/controller’, $data, ‘method’)

    Autoload uses module/config/autoload.php, and works the same as CI autoload for the module.

  • #473 / Jul 09, 2008 7:47am

    wiredesignz

    2882 posts

    Modular Extensions Version 4.2.01 is available on the wiki now.

    Refactored the code to give ME4.2 (PHP4) almost equivalent functionality to ME5.0 (PHP5)

    Note* $autoload[‘controllers’]; is now replaced with $autoload[‘modules’];

    As always, feedback is appreciated.

  • #474 / Jul 09, 2008 8:41am

    wiredesignz

    2882 posts

    Some features in Modular Extensions include:

    All controllers can contain an $autoload class variable, which holds an array of items to load prior to running the constructor. This can be used instead of module/config/autoload.php, however using the file takes precedence over the class variable.

    Modules::run() output is buffered, so any data returned or output directly from the controller is caught and returned to the caller. In particular, $this->load->view() can be used as you would in a normal controller, without the need for return.

    Controllers can be loaded as class variables of other controllers using $this->load->module(‘module/controller’); or simply
    $this->load->module(‘module’); if the controller name matches the module name.

    Any loaded module controller can then be used like a library, ie: $this->module_controller->do_stuff(), but it has access to its own models and libraries independently from the caller.

    Module controllers can have independent methods, located in a module/methods directory, these methods act as libraries extending their parent controller and have access to the parent controller features.

    Loading a method is achieved from a module controller by using $this->load->method(‘method’); or from a view by using modules:run(), if the method name is not defined in the controller then the method subclass will be loaded and its own index() method will be called, however if the controller actually has the method, it will be called as normal.

    Controllers also have a instance() method that can be used instead of get_instance() in libraries and helpers etc.
    ie: $ci = controller::instance();

    Of course all module controllers are accessible from the URL via module/controller/method or simply module/method if the module and controller names match.

    However if you add the _remap() method to your controllers you can prevent unwanted access to them and redirect or flag an error as you like.

    There are probably features that I have forgotten to mention, but I hope this sparks some interest.

  • #475 / Jul 09, 2008 9:45am

    codex

    332 posts

    @ wiredesignz:

    Maybe you should extend this information to the Wiki. I think the info there is not up to date and I feel it’s better to have all info regarding ME in one spot, not scattered around a 47-page forum topic.

    Also in general, what I *personally* would like to see is a faq section for each extension/plugin/hook/whatever. Just take questions you already have answered in the forum and put them as a question/answer combo in the wiki. The more info you give users, the less you have to spend time answering questions.

    ME is a wonderful tool, but I think due to the limited (or at least fragmented) documentation people tend not to use it (and go for Matchbox instead).

  • #476 / Jul 09, 2008 9:53am

    wiredesignz

    2882 posts

    Thnaks codex,

    I’m terrible at writing stuff like this, I just had a quiet moment available to myself to be able to write the previous post and that took me an hour.

    I have asked a couple of ME users to contribute some documentation, and you are welcome to help out if you wish.

    I can add the above post to the wiki, but it will probably not make a lot of sense with the other stuff there.

    EDIT:
    I don’t think the latest version of ME resembles the version 47 pages ago anyway. :lol:

  • #477 / Jul 09, 2008 10:25am

    wiredesignz

    2882 posts

    Wiki is updated. Copy and paste is wonderful.

  • #478 / Jul 09, 2008 4:54pm

    codex

    332 posts

    I have asked a couple of ME users to contribute some documentation, and you are welcome to help out if you wish.

    Well, to be honest I myself have abandoned ME for Matchbox (I feel bad for admitting).  Matchbox is just a bit easier to grasp/implement. But now there’s a job ahead in which ME fits the bill better, so I’m looking into using ME again. So maybe this time I *can* contribute.

    The addition in the Wiki is not exactly what I had hoped for, but at least it’s up to date. Thanks :coolsmirk:

  • #479 / Jul 09, 2008 8:55pm

    wiredesignz

    2882 posts

    You can use Modular Extensions in exactly the same fashion as Matchbox, without using any of the additional features ME provides.

  • #480 / Jul 09, 2008 9:27pm

    a&w

    101 posts

    From the camps of those intimidated by lack of (current) documentation…

    One thing that would be a good selling point is some docs for “How to convert your existing matchbox app to a ME app in 5 minutes/steps or less”.  Maybe I’m ignorant but the salesman makes it sound that easy.  😉

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

ExpressionEngine News!

#eecms, #events, #releases