We use cookies to improve your experience. No personal information is gathered and we don't serve ads. Cookies Policy.

ExpressionEngine Logo ExpressionEngine
Features Pricing Support Find A Developer
Partners Upgrades
Blog Add-Ons Learn
Docs Forums University
Log In or Sign Up
Log In Sign Up
ExpressionEngine Logo
Features Pro new Support Find A Developer
Partners Upgrades
Blog Add-Ons Learn
Docs Forums University Blog
  • Home
  • Forums

test your module for errors?

Development and Programming

SDuke's avatar
SDuke
11 posts
14 years ago
SDuke's avatar SDuke

I’ve been making a module and now need to test it for errors. How would I do this?

       
SDuke's avatar
SDuke
11 posts
14 years ago
SDuke's avatar SDuke

nobody?

       
SDuke's avatar
SDuke
11 posts
14 years ago
SDuke's avatar SDuke

I’ve tried installing it, yet that doesn’t work. It does add it to the esp_modules and add the tables I told it to, yet then it doesn’t say it’s installed and it apears that only the install function ran, here’s the code for the uploader :

<?php if (!defined('BASEPATH')) exit('No direct script access allowed');

class Upload_pictures_upd
{
    var $version='1.0';
    
    function Upload_pictures_upd()
    {
        $this->EE=& get_instance();
    }
    
        function tabs()
    {
        $tabs['upload pictures']=array(
            'upload_pictures_ids'=>array(
                'visible'         =>true,
                'collapse'         =>false,
                'htmlbuttons'     =>false,
                'width'             =>'100%'
            )
        );
        return $tabs;
    }
    
    function install()
    {
        $this->EE->load->dbforge();
        
        $data=array(
            'module_name'        =>'Picture uploader',
            'module_version'    =>$this->version,
            'has_cp_backend'    =>'y',
            'has_publish_fields'=>'y'
        );
        
        $this->EE->db->insert('modules',$data);
        
        $this->EE->load->library('layout');
        $this->EE->layout->add_layout_tabs($this->tabs(),'Upload_pictures');
        
        $fields = array(
            'id'    => array('type' => 'int', 'constraint' => '10', 'unsigned' => TRUE, 'auto_increment' => TRUE),
            'name'    => array('type' => 'varchar', 'constraint' => '250'),
        );
        
        $this->EE->dbforge->add_field($fields);
        $this->EE->dbforge->add_key('id', TRUE);
        
        $this->EE->dbforge->create_table('albums');
        
        unset($fields);
        
        $fields = array(
            'id'      =>array('type' => 'int', 'constraint' => '10', 'unsigned' => TRUE, 'auto_increment' => TRUE),
            'caption' =>array('type' => 'varchar', 'constraint' => '250'),
            'album'   =>array('type' => 'int','constraint'=>'10'),
            'thumbl'  =>array('type' => 'LONGBLOB'),
            'filename'=>array('type' => 'LONGBLOB')
        );

        $this->EE->dbforge->add_field($fields);
        $this->EE->dbforge->add_key('id', TRUE);
        
        $this->EE->dbforge->create_table('photos');
        
        return true;
    }

    function uninstall()
    {
        $this->EE->load->library("layout");
        $this->EE->db->query("DROP TABLE `exp_albums`");
        $this->EE->db->query("DROP TABLE `exp_photos`");
        $this->EE->db->query("DELETE FROM exp_modules WHERE module_name='Picture uploader'");
        $this->EE->layout->delete_layout_tabs($this->tabs(),'Upload_pictures');
        return true;
    }
    
    function update($current='')
    {
        return false;
    }
    
}
       
Focus Lab Dev Team's avatar
Focus Lab Dev Team
1,129 posts
14 years ago
Focus Lab Dev Team's avatar Focus Lab Dev Team

Hey SDuke

In your install() method the module name must match the class name. Try changing it to the class name and install again.

       
SDuke's avatar
SDuke
11 posts
14 years ago
SDuke's avatar SDuke

ok, I tried that yet it still does the same thing? Is there any other possible error, maybe in another script? Also I updated the code with what it is now. Also, thanks for the help.

       
Focus Lab Dev Team's avatar
Focus Lab Dev Team
1,129 posts
14 years ago
Focus Lab Dev Team's avatar Focus Lab Dev Team
ok, I tried that yet it still does the same thing? Is there any other possible error, maybe in another script? Also I updated the code with what it is now. Also, thanks for the help.

Out of curiosity, does the following code work?

<?php if (!defined('BASEPATH')) exit('No direct script access allowed');

class Upload_pictures_upd
{
    var $version='1.0';
    
    function Upload_pictures_upd()
    {
        $this->EE=& get_instance();
    }
    
        function tabs()
    {
        $tabs['upload pictures']=array(
            'upload_pictures_ids'=>array(
                'visible'         =>true,
                'collapse'         =>false,
                'htmlbuttons'     =>false,
                'width'             =>'100%'
            )
        );
        return $tabs;
    }
    
    function install()
    {
        $this->EE->load->dbforge();
        
        $data=array(
            'module_name'       =>__CLASS__,
            'module_version'    =>$this->version,
            'has_cp_backend'    =>'y',
            'has_publish_fields'=>'y'
        );
        
        $this->EE->db->insert('modules',$data);
        
        $this->EE->load->library('layout');
        $this->EE->layout->add_layout_tabs($this->tabs(),__CLASS__);
        
        $fields = array(
            'id'    => array('type' => 'int', 'constraint' => '10', 'unsigned' => TRUE, 'auto_increment' => TRUE),
            'name'    => array('type' => 'varchar', 'constraint' => '250'),
        );
        
        $this->EE->dbforge->add_field($fields);
        $this->EE->dbforge->add_key('id', TRUE);
        
        $this->EE->dbforge->create_table('albums');
        
        unset($fields);
        
        $fields = array(
            'id'      =>array('type' => 'int', 'constraint' => '10', 'unsigned' => TRUE, 'auto_increment' => TRUE),
            'caption' =>array('type' => 'varchar', 'constraint' => '250'),
            'album'   =>array('type' => 'int','constraint'=>'10'),
            'thumbl'  =>array('type' => 'LONGBLOB'),
            'filename'=>array('type' => 'LONGBLOB')
        );

        $this->EE->dbforge->add_field($fields);
        $this->EE->dbforge->add_key('id', TRUE);
        
        $this->EE->dbforge->create_table('photos');
        
        return true;
    }

    function uninstall()
    {
        $this->EE->load->library("layout");
        $this->EE->db->query("DROP TABLE `exp_albums`");
        $this->EE->db->query("DROP TABLE `exp_photos`");
        $this->EE->db->query("DELETE FROM exp_modules WHERE module_name='".__CLASS__."'");
        $this->EE->layout->delete_layout_tabs($this->tabs(),__CLASS__);
        return true;
    }
    
    function update($current='')
    {
        return false;
    }
    
}
       
SDuke's avatar
SDuke
11 posts
14 years ago
SDuke's avatar SDuke

no, sorry. With the installation process does it just check this file or will I have to debug all the other 5 or 6 scripts that are required too?

       
Wouter Vervloet's avatar
Wouter Vervloet
758 posts
14 years ago
Wouter Vervloet's avatar Wouter Vervloet

What I usually do to debug is strip it down to its most basic form and add from there until it breaks. Then I know exactly where things go wrong.

Try this first and keep adding code back in until it breaks.

function install()
    {
        
        $data=array(
            'module_name'       =>__CLASS__,
            'module_version'    =>$this->version,
            'has_cp_backend'    =>'y',
            'has_publish_fields'=>'y'
        );
        
        $this->EE->db->insert('modules', $data);
        
        return TRUE;
    }

Also, as of EE 2.1.2 PHP4 support has ended, which means they’re using PHP5 constructors now (__construct). I usually add both for backwards compatibility:

function Upload_pictures_upd()
{
  $this->__construct();
}

function __construct()
{
  $this->EE=& get_instance();
}
// END __constructor

Wouter

       
GDmac - expocom's avatar
GDmac - expocom
350 posts
14 years ago
GDmac - expocom's avatar GDmac - expocom

Like Wouter said, start with the most basic form. A good starting point for that is http://pkg.io/

       
SDuke's avatar
SDuke
11 posts
14 years ago
SDuke's avatar SDuke

@Wouter thanks for that tip I’ll remember that.

@GDmac that worked, thanks, yet I’d still like to find out what I did wrong so I don’t do it again.

       
SDuke's avatar
SDuke
11 posts
14 years ago
SDuke's avatar SDuke

Also with the mcp will you have to use js to make the backend page?

       
Click Rain 1's avatar
Click Rain 1
9 posts
14 years ago
Click Rain 1's avatar Click Rain 1

Far as I know, there’s nothing forcing you to utilize JS to make a CP backend page. I believe you can submit any form you generate on the CP page to the action URL for your module, documented here.

       
Click Rain 1's avatar
Click Rain 1
9 posts
14 years ago
Click Rain 1's avatar Click Rain 1

Not to belabor this, but I think you’ll want to use the module’s “primary” class name–in this case “Upload_pictures”–instead of the update file’s class name (“Upload_pictures_upd”), which is what you’d get if you used CLASS.

So I think something like this would be more appropriate in the install() method:

$data=array(
            'module_name'        =>'Upload_pictures',
            'module_version'    =>$this->version,
            'has_cp_backend'    =>'y',
            'has_publish_fields'=>'y'
        );

Guys, please speak up if I’m wrong.

Something else you may be interested in for debugging is Experience Internet’s OmniLog module. It looks promising.

       
Focus Lab Dev Team's avatar
Focus Lab Dev Team
1,129 posts
14 years ago
Focus Lab Dev Team's avatar Focus Lab Dev Team
…I think you’ll want to use the module’s “primary” class name–in this case “Upload_pictures”–instead of the update file’s class name (“Upload_pictures_upd”), which is what you’d get if you used __CLASS__.

Excellent point. I responded quickly thinking about Extensions, not modules. Pardon my error.

       

Reply

Sign In To Reply

ExpressionEngine Home Features Pro Contact Version Support
Learn Docs University Forums
Resources Support Add-Ons Partners Blog
Privacy Terms Trademark Use License

Packet Tide owns and develops ExpressionEngine. © Packet Tide, All Rights Reserved.