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.

[Deprecated] DMZ 1.6.2 (DataMapper OverZealous Edition)

November 23, 2009 11:54pm

Subscribe [46]
  • #166 / Jan 12, 2010 1:54am

    Jakebert

    15 posts

    Super question, probably stupid:

    is it possible to have one model cater to two different controllers? Let’s say I’ve got my student model, and then my students controller (which handles CRUD/admin) and my student controller, so that users can view individual profiles without having access to the admin/CRUD stuff. Is that possible? Right now I’m getting a cannot redeclare class error in the model.

  • #167 / Jan 12, 2010 1:56am

    OverZealous

    1030 posts

    @Jakebert

    This is your answer.

    😊

  • #168 / Jan 13, 2010 11:00am

    Alface

    41 posts

    to use DMZ with HMVC I hacked datamapper libraries (system\application\libraries)
    I couldn’t extend without losing the functionality to make a custom datamapper’s extended class for each module
    actily, I think it is not even possible to extend autoload datamapper native class.

    static function autoload($class)
        {
            // Don't attempt to autoload CI_ or MY_ prefixed classes
            if (in_array(substr($class, 0, 3), array('CI_', 'MY_')))
            {
                return;
            }
    
            // Prepare class
            $class = strtolower($class);
    
            // Seach on application folder
            // Prepare path
            $path = APPPATH . 'models';
    
            // Prepare file
            $file = $path . '/' . $class . EXT;
            
            
            // Check if file exists, require_once if it does
            if (file_exists($file))
            {
                require_once($file);
            }
            else
            {
                // Do a recursive search of the path for the class
                DataMapper::recursive_require_once($class, $path);
            }
            
            
            
            // Seach on Modules folders
            
            // Prepare path
            $path = APPPATH . 'modules';
            
            if(is_dir($path) ){
                if ($handle = opendir($path)){
                    while (FALSE !== ($dir = readdir($handle))){
                        // If dir does not contain a dot
                        if (strpos($dir, '.') === FALSE){
                            $modules[] = $dir;
                        }
                    }
                }
            }
            
            foreach($modules as $module){
                // Prepare path
                $path = APPPATH . 'modules/'.$module.'/models';
                
                // Verify if there is a models folder on Module folder
                if(is_dir($path) ){
                    // Prepare file
                    $file = $path . '/' . $class . EXT;
        
                    // Check if file exists, require_once if it does
                    if (file_exists($file))
                    {
                        require_once($file);
                    }
                    else
                    {
                        // Do a recursive search of the path for the class
                        DataMapper::recursive_require_once($class, $path);
                    }
                }
            }
        }

    I needed to edit system\application\datamapper\htmlform.php too
    turn it

    // this is the default template (view) to use for the overall form 
        var $form_template = 'dmz_htmlform/form';
        // this is the default template (view) to use for the individual rows
        var $row_template = 'dmz_htmlform/row';
        // this is the default template (view) to use for the individual rows
        var $section_template = 'dmz_htmlform/section';

    intro this

    // this is the default template (view) to use for the overall form 
        var $form_template = '../dmz_htmlform/form';
        // this is the default template (view) to use for the individual rows
        var $row_template = '../dmz_htmlform/row';
        // this is the default template (view) to use for the individual rows
        var $section_template = '../dmz_htmlform/section';

    I think it will work with any Modular Extension (ME) like Matchbox.
    I didn’t find any post about it on the forum, if anyone know a better way to do it, let me know

  • #169 / Jan 14, 2010 6:32am

    Oblique

    32 posts

    Incorrect value in htmlform-generated dropdown

    Instead of id’s from DM’s i supplied, dropdown value attrubutes are set to 0-1-2-3 and so on;

    I set up rendering like this:

    $driver_fields = array
        (
            'Driver' => 'section'
            ,'name' => array('value' => '')
            ,'phone' => array('value' => '')
            ,'passport' => array('value' => '')
            ,'existing_driver' => array
                (
                    'label' => 'Already existing'
                    ,'type' => 'dropdown'
                    ,'list' => $client->driver
                )
        );

    and then:

    <?= $client->driver->render_form($driver_fields ,'' ,array(), 'dmz_htmlform/form_fragment') ?>

    Renderer gives me this:

    <select name="existing_truck" id="existing_truck">
    <option value="0" selected="selected">Driver_6</option>
    <option value="1">Driver_15</option>
    ...
  • #170 / Jan 14, 2010 7:11am

    chadbob

    11 posts

    I need some HTML form extension help…I’ve got it working and saving forms, but it’s missing one of my relationships.


    Here is my DB table structure:

    locations
    locations_statutes
    reports (reports has an in table foreign key for location)
    reports_statutes
    statutes

    Everything works as normal when reading from the DB.

    When the HTML form extension saves a report, a new report table entry is made, and reports_statutes is updated with the relationship, but it doesn’t update the locations_statutes table with that relationship.

    Here are the field snippets from my code:

    // This is how are form will be rendered
           $form_fields = array(
                 'id',
                // Section header
                'Report Contents' => 'section',
                'date',
                'description',
    
                // Section header
                'Locations and Statutes' => 'section',
                'location',
                'statute'
    // Use the (already-loaded) array extension to process the POSTed values.
               $rel = $rep->from_array($_POST, array(
                       'id',
                    // Section header
                    'section',
                    'date',
                    'description',
                    'location',
                    'statute'
  • #171 / Jan 14, 2010 7:30am

    OverZealous

    1030 posts

    To All: (Regarding the HTML Form extension)

    I understand that the HTML form extension is very useful to many people.  However, I do not have the time to maintain it or support it.

    I would like to find someone who is willing to take over maintenance and support for this extension.  It needs some work, and I just barely have enough time to keep up with the work on the core DMZ library.

    If you are interested in maintaining it, please let me know (either through a PM or right here).  Just to be clear, everything I have for this extension is already included in the full DMZ download (including the documentation), so if you are interested, feel free to look at the source directly.

    I would be willing to include someone else’s work with the full download, or pull the HTML extension out of the core download, and link to it somewhere else.  The latter is probably preferable, since I won’t necessarily upgrade DMZ on the same schedule as the HTML form extension.

  • #172 / Jan 14, 2010 8:21am

    The Hamburgler

    28 posts

    Datamapper has made my job a breeze recently so I guess its time I gave something back!

    I’ve been working on my own CodeIgniter Table and Form libraries: GoodForm and BadTable, for a while now since most of my work is based around CMS web apps.

    Both libraries have been designed to work standalone but I have also included DMZ extension files to add their functionality to DM Models.

    If any one is interested please download a copy from my site and have a play… There will be bugs, but as i’m currently developing with both systems I should be able to provide fixes pretty quickly.

    PM me if you have any questions.

    Jim

  • #173 / Jan 14, 2010 11:20am

    Samos

    1 posts

    Hi I want to thank you for the library, I just started with codeigniter and keep getting an error in the datamapper.


    I get the following error when calling delete of the datamapper.

    Fatal error: Class 'post' not found in C:\Users\Samos\xampp\htdocs\productReview\system\application\libraries\datamapper.php on line 1292

    The strange thing is that it deletes the record out of the database, but produces this error.

    function delete($object = '', $related_field = '')
        {
            if (empty($object) && ! is_array($object))
            {
                if ( ! empty($this->id))
                {
                    // Begin auto transaction
                    $this->_auto_trans_begin();
    
                    // Delete this object
                    $this->db->where('id', $this->id);
                    $this->db->delete($this->table);
    
                    // Delete all "has many" and "has one" relations for this object
                    foreach (array('has_many', 'has_one') as $type) {
                        foreach ($this->{$type} as $model => $properties)
                        {
                            // Prepare model
                            $class = $properties['class'];
                            $object = new $class();


    $object = new $class(); That is the line where it gives the error.


    This is the code how i call the delete:

    if($this->input->post('subDelete'))
                {
                    //$id = $this->input->post('id');
                    $category->id = 1;
                    $category->get()->delete();
                }


    Probably it is my fault as i am new to codeigniter, but was hoping to get support maybe here as this is the datamapper thread.

  • #174 / Jan 14, 2010 10:19pm

    OverZealous

    1030 posts

    3rd-Party Extensions

    I’ve been meaning to figure out how to handle 3rd-Party Extensions.  I don’t really want to set something up on my own server, since that would be yet another account for everyone to manage.

    Instead, I’m thinking of using the existing CodeIgniter Wiki with a special category.

    The idea is to have everyone write a Wiki page for their extension, and then make sure it is included in the DMZ Extensions category.

    Then I will link to the that page from the DMZ Manual.  I figure using a category is best, because then the extensions are listed alphabetically, and it reduces the temptation to resort other people’s extensions. 😉

    I’ve already added links to the 4 included extensions I still support.  I might have found someone to take over the HTML Form extension, but still let me know if you are interested.

  • #175 / Jan 15, 2010 4:59pm

    lexxxluthor

    1 posts

    Is it possible to use DMZ with multiple database connections? If so, how? I can’t seem to locate anything in the documentation about that. 😊 Thank you for your patience and your reply.

  • #176 / Jan 15, 2010 6:00pm

    OverZealous

    1030 posts

    @lexxxluthor

    See the $db_params property.  It is not officially supported, but feel free to try it out.

    If you didn’t know, you can search the manual.  Searching for “multiple database” leads to the first post of this forum, where it explicitly says:

      4. While not tested, it should be easier that ever to work with multiple databases simultaneously.  (You won’t be able to query across them, but no more hacking to get a different DB for different objects!)  See db_params on this page.

  • #177 / Jan 18, 2010 4:02pm

    lsemel

    18 posts

    Suggestion for DMZ:

    I have been using DMZ Datamapper on large results sets (100,000s of rows) and it quickly runs out of memory because CI loads results sets in full.  As a workaround, I’ve been using this pattern:

    $model = new Model_Object();
    # A query returning a big result set.  Instead of calling get(), call get_sql()
    $sql = $model->..where clauses,etc….->get_sql();
    $results = $this->db->query($sql);
    if ($results->num_rows() > 0) {
       # Iterate through the rows without loading the full result set
       while($row = $results->_fetch_object()) {
          # Do something with the row
       }
    }

         
    It might be useful for anyone dealing with large result sets if this pattern were part of the library.  In place of get, you could call something like get_cursor() and then to read rows you could call something like fetch() which will return a model object populated with the next row.  If you did not generate your query with get_cursor(), then fetch() would throw an error.

  • #178 / Jan 18, 2010 5:18pm

    Muser

    78 posts

    Thanyou Isemel,

    We have to deal with a big result quite soon in a project (I wish) and your suggestion might be very useful

  • #179 / Jan 18, 2010 5:26pm

    lsemel

    18 posts

    It might work as a plugin, save for the fact we’d probably want all the get_* methods to work properly.

  • #180 / Jan 18, 2010 9:31pm

    OverZealous

    1030 posts

    @Isemel, Muser

    You may want to have a look at TheJim’s solution to this problem.  That, and the following post or two, show a way to magically loop over a result set while creating only one object in memory.

    It’s a slick idea, and doesn’t mix standard result set processing with DMZ-style processing.  Of course, if you only need the results of the query, that’s fine too!

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

ExpressionEngine News!

#eecms, #events, #releases