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]
  • #106 / Dec 20, 2009 3:23pm

    janus303

    10 posts

    (Line 1400)
        function _delete($related_field, $arguments)
        {
            $this->delete($arguments[0], $related_field);
        }

    This should have a return so we pass through the success/failure when deleting relations.

    I was just about to make the same observation. This manifested itself in the case of deleting a required relation and then saving the object with a new relation. The result of the save was an error that the relation was required, even though the operation was saving the relation. Simple fix that vexed me for more time than it should have had I noticed your post first. 😊

    To clarify for the next hapless sap like me, that function should be modified thusly:

    (Line 1400)
        function _delete($related_field, $arguments)
        {
            return ($this->delete($arguments[0], $related_field));
        }
  • #107 / Dec 21, 2009 1:36am

    tdktank59

    322 posts

    So im having some issues with muti lingual stuff…

    Under the validation im trying to use my method from the language class that looks up translations for labels.

    var $validation = array(
            'username' => array(
                'rules' => array(
                    'required',
                    'trim',
                    'min_length' => 4,
                    'max_length' => 25,
                    'unique'
                ),
                'label' => $this->lang->db_line('username')
            ),
    [excerpt…]

    For some reason it is throwing the error

    [21-Dec-2009 00:28:35] PHP Parse error:  syntax error, unexpected T_VARIABLE in {site_url}/application/models/user/user.php on line 60

    yet nothing looks wrong…

  • #108 / Dec 21, 2009 5:14am

    OverZealous

    1030 posts

    @tdktank59
    You cannot use $this outside of an instantiated object.  Look at your code.  The place you are in is before the Object (the model) has been created.

    If you want to dynamically assign language-based labels, you’ll have to do them within the object constructor (__construct), before you call parent::__construct().

    At some point in the future I’ll add in language-based labels.  Make sure you are not using the production cache with language based labels.  They will be cached as whatever language you start with.

  • #109 / Dec 21, 2009 5:16am

    tdktank59

    322 posts

    @tdktank59
    You cannot use $this outside of an instantiated object.  Look at your code.  The place you are in is before the Object (the model) has been created.

    If you want to dynamically assign language-based labels, you’ll have to do them within the object constructor (__construct), before you call parent::__construct().

    At some point in the future I’ll add in language-based labels.  Make sure you are not using the production cache with language based labels.  They will be cached as whatever language you start with.

    Yeah cache is off at the moment due to the fact that im still in development.

    This is in the model… and yes PHP5 is on
    Ill make a work around some how… Need to be able to display error messages with the translated values… (BTW I posted up the Spanish Version of the lang file.)

    function __construct($id = NULL)
        {
            parent::__construct($id);
        }
  • #110 / Dec 21, 2009 5:18am

    The Hamburgler

    28 posts

    I’ve had this issue before when ever i’ve needed to call a function outside of a method. It seems to be a php limitation as I don’t think “$this” exists until your class has been constructed.

    Easiest way around it is to move the code into your class __construct()

  • #111 / Dec 21, 2009 5:31am

    OverZealous

    1030 posts

    This has nothing to do with PHP

    This is basic Object Oriented Programming stuff.  You are trying access the $this variable — a variable that refers to an instantiated object — but in a static context.

    The only things you can refer to in a static context are global methods, static properties, and other static methods.

  • #112 / Dec 21, 2009 9:48am

    cahva

    662 posts

    I have solved the lang problem by creating a new method which sets the validation:

    class Customer Extends DataMapper {
        var $table = 'customers';
        var $has_one = array('group');
        var $has_many = array('addressbook');
        var $validation = array();
    
        function __construct()
        {
            parent::__construct();
            $this->_set_validation();
        }
    
        function _set_validation()
        {
            $this->validation = array(
                'name' => array(
                    'label' => lang('account.name'),
                    'rules' => array('required', 'trim', 'max_lenght' => 255)
                ),
                'email' => array(
                    'label' => lang('account.email'),
                    'rules' => array('required', 'trim', 'unique', 'max_length' => 255, 'valid_email')
                ),
    ....
    ....
  • #113 / Dec 21, 2009 12:01pm

    Muser

    78 posts

    I don’t know if it is a bug or I have missed a step… but I’ve upgraded from 1.4.0 to 1.6.1 and when I’ve tried to load the page I have got this error:

    Fatal error: Call to a member function load() on a non-object in C:\webs\xampp\htdocs\grera\application\libraries\datamapper.php on line 615

    I have checked the line 615:

    if($name == 'form_validation')
            {
                $CI =& get_instance();
                if( ! isset($CI->form_validation))
                {
                    $CI->load->library('form_validation');
                }
                $this->form_validation = $CI->form_validation;
                $this->lang->load('form_validation');
                return $this->form_validation;
            }

    Maybe it should be this?

    if($name == 'form_validation')
            {
                $CI =& get_instance();
                if( ! isset($CI->form_validation))
                {
                    $CI->load->library('form_validation');
                }
                $this->form_validation = $CI->form_validation;
                [b]$CI->lang->load('form_validation');[/b]
                return $this->form_validation;
            }
  • #114 / Dec 21, 2009 1:33pm

    OverZealous

    1030 posts

    @Muser
    The only way this could happen is if you are trying to access $this->form_validation before calling parent::__construct() in your model’s constructor.

    This is not a problem with DMZ.

  • #115 / Dec 21, 2009 3:41pm

    Muser

    78 posts

    @tdktank59: I have corrected some orthography and gramatical errors on your spanish lang file.

    Also, I have posted a catalan lang file.

  • #116 / Dec 21, 2009 6:00pm

    OverZealous

    1030 posts

    Thanks for the language files, Muser and tdktank59.  I’ve added them to the distribution.

    If anyone else out there would like to provide localized error messages, I would be very appreciative!

    Out of curiosity, what naming structure would you prefer for the language folders:

    1) Use the English names for the languages:

    catalan/
    english/
    spanish/

    2) Use the native names for the languages (in unaccented ASCII characters):

    catala/
    english/
    espanol/

    3) Use the ISO-639-1 2-letter codes:

    ca/
    english/ (for CI compatibility)
    es/

    Personally, I prefer #3 whenever possible.  In fact, if I ever localize my application, I would be tempted to use an RFC 5646 structure like this:

    ca/
    en/
    en-US/
    en-GB/
    es/
    es-ES/
    es-MX/
    ...
  • #117 / Dec 23, 2009 12:22am

    chadbob

    11 posts

    get isn’t working for me when inside of a helper…I’m stumped!


    The rest of my CI/DMZ app works perfectly fine, with get statements inside of controllers, however I have something that will be used everywhere, so I want to put it into a custom helper.


    I’ve made it as simple as I can, and the problem still happens:

    $p = new Report();
    $p->get();
    return count($p->get());

    In a helper, that always returns “1”.  Which is wrong.

    However, those three lines in a controller always return the accurate count…I’m not sure what’s going on.  Is there something with the helper system that prevents DMZ from working correctly in this scenario?

  • #118 / Dec 23, 2009 12:58am

    OverZealous

    1030 posts

    @chadbob

    I doubt those exact lines work differently in your controller.

    There is nothing wrong with what it is returning.  Because you are calling get a second time, there is only one item in the array.

    Your code should look like this:

    $p = new Report();
    $p->get();
    return count($p->all);

    EDIT: Made a slight change to count ->all explicitly.

  • #119 / Dec 23, 2009 1:10am

    chadbob

    11 posts

    @chadbob

    I doubt those exact lines work differently in your controller.

    There is nothing wrong with what it is returning.  Because you are calling get a second time, there is only one item in the array.

    Your code should look like this:

    $p = new Report();
    $p->get();
    return count($p->all);

    EDIT: Made a slight change to count ->all explicitly.

     

    Sorry, that was a typo in my post, I should have copied/pasted.

    My code is indeed:

    $p = new Report();
    $p->get();
    return count($p->all);


    It will only give me the first report by date (this auto sort is spec’d in the model).

    However in a controller, it gives me all of them.


    I’ve even made a new helper and a new controller just to see, and with different names for the objects.  Same deal.

    Another thing I tried is that a get where works in the helper:

    ex:

    $p->where('id', 4)->get();

    I can change that number, and I always get the correct report.  But the minute a get should return more than one, and it’s in a helper, it just spits out the first report in line.

  • #120 / Dec 23, 2009 1:18am

    OverZealous

    1030 posts

    Make 100% sure you are doing this: count($p->all) and not this: count($p).  I just tested it to be sure, and the latter always returns 1.

    I’ve got helpers all over, and have never seen anything like this.  It just doesn’t make sense, since $p->all is a normal PHP array, and count is an internal PHP function.

    Is the Datamapper library getting loaded correctly before it is used in your helper?  Are you sure that $p is a valid object?

    Again, I just tested it, using almost exactly the same code.  Works perfectly for me.

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

ExpressionEngine News!

#eecms, #events, #releases