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.

DMZ 1.7.1 (DataMapper OverZealous Edition)

March 14, 2010 11:43pm

Subscribe [104]
  • #391 / Jun 30, 2010 10:16pm

    lexusgs430

    49 posts

    Hi,

    Im trying to use query string + pagination and I cant seem to get it working quite right. It is returning the number of results correctly and what not, but actually navigating to the pages (ie page 2) within the results, I cannot figure out how. Ive been trying to figure out the right way to access the pages but no luck.

    Can anyone tell me whether its possible to use querystrings + pagination or if its just not going to work?

    For example -

    I have a controller called search and a function called query

    the url of results looks like this-  search/query?search=mens+watch

    Which is working, but accessing the pages of the result isnt.

  • #392 / Jun 30, 2010 10:19pm

    OverZealous

    1030 posts

    @lexusgs430
    Are you referring to the DMZ’s pagination code?  DMZ’s code doesn’t handle rendering the pagination.  It merely handles getting pages of results, and gives you a ton of variables to help.

    If you are referring to the CodeIgniter library, that is not part of DMZ, and should be asked elsewhere.

    (In either case, CodeIgniter doesn’t support query strings by default.  You have to hack the Input library to get them working.)

  • #393 / Jul 01, 2010 3:13am

    NachoF

    171 posts

    Thank you Phil, I have finally figured it out using always_validate and a custom zero_on_empty function

    I have now a question regarding the unique_pair validation method.. how can I make it work with relations?

    Heres the model structure, a project has many stages, and each stage has a year field.. so basically, a project shouldnt have two stages with the same year value…

    On my stage model I have

    var $validation = array(
            'year' => array(
                'label' => 'Year',
                'rules' => array('required', 'trim', 'numeric','unique_pair' => 'project_id')
                ),

    Is that the right approach or should I somehow do something that doesnt involve the project_id but the project object itself?? please help.

  • #394 / Jul 01, 2010 11:27am

    OverZealous

    1030 posts

    @NachoF
    You could try this, but this should be enforced through business logic, not through field rules.  That’s not what they are meant for.

  • #395 / Jul 01, 2010 1:26pm

    NachoF

    171 posts

    @NachoF
    You could try this, but this should be enforced through business logic, not through field rules.  That’s not what they are meant for.

    well, I tried it but after doing

    $stage->save($project)

    it doesnt seem to valiadate it…. just to check I changed the unique_pair value to another value in the stage table and that works so Im clueles on how to get it done?? maybe with a related validation rule?

  • #396 / Jul 01, 2010 1:32pm

    OverZealous

    1030 posts

    @NachoF
    You just have to write some code!  Like I said, not through [validation] rules.

  • #397 / Jul 01, 2010 1:36pm

    NachoF

    171 posts

    @NachoF
    You just have to write some code!  Like I said, not through [validation] rules.

    its not about not wanting to write code… its about doing it the most elegant way….Checking that the project doesnt already have a stage with that year value is trivial to write.. I just dont think its something that belongs in my controller…. I dont understand why you say its not a validation issue when you defined the function unique_pair

  • #398 / Jul 01, 2010 1:45pm

    OverZealous

    1030 posts

    @NachoF

    I didn’t define the function - it’s from DataMapper.  And it’s designed to work with normal fields.  It’s designed specifically to mirror the functionality of a compound primary key.

    The reason field validation rules won’t work against relationships is that the relationships aren’t set until after the object has been saved.  You might be able to make a related validation rule work, but I don’t usually do much with those.

    The reason I think this absolutely belongs in a controller is this is a business logic function.  This is something that needs to be enforced through application logic.  I don’t understand why it would ever be possible for the user to pick an invalid combination in this instance.  In general, it’s more a matter of opinion, and design choice.

  • #399 / Jul 02, 2010 11:35am

    Quaotloa

    3 posts

    Hi.
    I tried to use datamapper, but I only get this error, when i try to create models..
    Fatal error: Class ‘DataMapper’ not found in /Applications/MAMP/www/application/models/_template.php on line 22

    If i try to remove _template.php file, I get no errors, until i create a new model, where I inherit from DataMapper.. Then i get the same error, with a reference to another file of course..


    Why do this error occour? Eclipse do find DataMapper, so the file is there, and I have followed the installation guide..

  • #400 / Jul 04, 2010 8:52am

    happydude

    45 posts

    I just set up my datamapper models and when trying to initiate any one of them in my controller (e.g. $request = new Request() ), I get this error message:

    Fatal error: Cannot access empty property in C:\Users\Scofield\Documents\My Dropbox\Dev\xampp\htdocs\dma\system\application\libraries\datamapper.php on line 2352

    Any help rendered will be greatly appreciated

  • #401 / Jul 04, 2010 12:47pm

    OverZealous

    1030 posts

    @happydude
    http://www.overzealous.com/dmz/pages/troubleshooting.html#General.Plural.Controller

    Also, please try doing a little troubleshooting.  There are tips at the top of that page.

  • #402 / Jul 04, 2010 7:57pm

    sqwk

    83 posts

    Is there away to set up a relationship between two tables in two databases? (on the same server, with the same login credentials)

  • #403 / Jul 04, 2010 9:36pm

    OverZealous

    1030 posts

    @squawk
    Nope.  DMZ needs both objects on the same database.

    However, you could manually simulate the connection.  It’s not officially supported, but DMZ has the ability to talk to multiple databases.  There’s just no way for it to understand the relationship.

  • #404 / Jul 06, 2010 4:20am

    Hi people, and hi OverZealous. I belive this is my very first post. Beeing a front end developer who the last year or so have started to pay interest for php, oop and CI I can’t tell you enough how much this forum has helped me. Yet I have coded very little, mostly been reading, and it’s a great feeling for someone at my (low) level to actually feel that something is being learnt. It feels like I’m slowly getting a grip on things.

    Your forum posts, OverZealous, and the documentation for DMZ, has helped me so much. So I just want to give you a big thank you. Two other users from which contributions I also learned a great deal is wiredesignz and dexcell. So big thanks to these guys as well. I guess this probably should be in another thread, but from the beginning I was just about to thank you OverZealous for DMZ 😊

    Take care, and keep up the fantastic work! I might be back with some silly questions later on!

  • #405 / Jul 06, 2010 10:32pm

    sqwk

    83 posts

    I’ve got a bit of trouble with relationships:

    $b = new Buyer();
    $b->order_by('updated', 'desc')->get($limit, $offset);
    $b->user->get();
    $b->place->get();
    $b->objtype->get();

    Foreaching through $b works fine and I can echo all the fields from the buyers table, however, ALL of the relationship fields (like $buyer->user->username or $buyer->objtype->name) are empty. I checked that all the relationships are set up right in the models

    All the fields from the joined tables are set, it is just that they are empty. Or am I accessing them wrong?

    The other thing that I noticed is that all the queries from the joined tables seem to have an additional WHERE clause. (What are they for?)

    WHERE `ksv_buyers`.`id` = 353

    353 is the id of the first record that is being returned. The relationship fields are also not filled for this record.