My Sample Add-On

  • I am trying to wrap my head around creating custom Add-Ons, and without tweaking anything from the download when I implement

    PHP
    1. <?php my_sample_detail(); ?>

    it throws this error

    Code
    1. Warning: Missing argument 1 for my_sample_detail(), called in /public_html/page/index.php on line 54 and defined in public_html/login/addons/apps/my_sample/runtime.php on line 71

    I am unsure how to fix.

  • drewm

    Approved the thread.
  • Here is what is in the runtime.php

  • Hello! Me again!


    I am finally starting to get my head around this! But I have run into another snag. Sorry in advance for being a pain! Just trying to learn everything perch has to offer!


    I have added a my_sample_listing_custom to the runtime.php

    Code
    1. function my_sample_listing_custom($opts=false, $return=false)
    2. {
    3. return my_sample_listing($opts, $return);
    4. }

    But When I do the Function on the index.php the only thing is seems to listen to is the template

    Code
    1. my_sample_listing_custom(array(
    2. 'filter' => 'thingTitle',
    3. 'match' => 'contains',
    4. 'value' => '1',
    5. 'template' => 'listing_custom.html',
    6. 'count' => '2',
    7. ));

    It doesn't throw and error or anything it just returns everything as it would for my_sample_listing, except it will change to the template I specify.

    What am I missing?


    Again, sorry for being a pain!

  • This is it! TYIA!

  • hus_hmd


    Thank you for pointing this out! Do you have any suggestions on how to fix this? I have tried multiple things and I just can't get it.


    My full runtime.php is below

  • I replaced

    PHP
    1. $Things = new MySample_Things($API);
    2. $list = $Things->all();

    with

    PHP
    1. $Things = new MySample_Things($API);
    2. $filtered_things = $Things->get_filtered_listing($opts);

    and it didn't return anything

    I also tried


  • If you enable debug mode, what does the debug message say?


    You can add marks to the debug message so it's easier to spot the relevant lines:


    PHP
    1. PerchUtil::mark('Start');
    2. $Things = new MySample_Things($API);
    3. $filtered_things = $Things->get_filtered_listing($opts);
    4. PerchUtil::mark('End');


    You can refer to first-party apps like the Blog app to see how they handle the filtered listing. Though they may include code that isn't relevant to your app.

  • This is the messages that comes out

    and when I change to


    the debug message returns this



    Code
    1. Array
    2. ( [type] => 8 [message] => Use of undefined constant my_sample - assumed 'my_sample' [file] => /home1/twoperc6/public_html/login/config/apps.php [line] => 2
    3. )


  • Ok I fixed all those errors but It's still not returning anything.


    Debug

    Code
    1. ------------------------------ Start ------------------------------
    2. [2] SELECT SQL_CALC_FOUND_ROWS DISTINCT main.* FROM perch3_my_sample_things main WHERE 1=1 ORDER BY thingDateTime ASC LIMIT 0, 2
    3. [3] SELECT FOUND_ROWS() AS `count`
    4. [2] Using template: /addons/apps/my_sample/templates/listing.html
    5. ------------------------------ End ------------------------------
    6. [0] Using template: /addons/apps/my_sample/templates/sample/listing.html


    Current runtime.php

  • get_filtered_listing() should render the template for you. So you don't need to render it inside my_sample_listing().


    Take it one step at a time and iterate on your changes. You've added get_filtered_listing() and you can see the database query it's making in your debug message. I'm assuming you have some rows in the table perch3_my_sample_things.


    The next step for you would be to check what get_filtered_listing() returns. You're assigning what it returns to the variable $filtered_things. Inspect what this variable holds. Is it what you expect?



    This may help:

  • So I reverted back to clean my_sample files to try and locate the issue and tried to rework with your above code. And it does return items it just returns them empty.



    Debug

    SQL
    1. SELECT main.* FROM perch3_my_sample_things main WHERE 1=1 ORDER BY thingDateTime ASC
    2. [3] Using template: /addons/apps/my_sample/templates/listing.html