Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Try Vanilla Forums Cloud product

Ready to contribute?

Amazing! Sign our contributors' agreement and then join us on GitHub.

Vanilla 2.3 fully supports PHP 7. Get it now!
Please upgrade to 2.3 here. The 2.2 and earlier branches are no longer being updated.

[Solved] [Documentation] Need help writing an application

edited April 2012 in Vanilla 2.0 - 2.2

Hi all,

I'm trying to write an Application. I'm using http://vanillaforums.org/docs/appquickstart as my guide.

I copy/pasted the applications/skeleton/ directory and changed everywhere the word 'skeleton' existed in that directory to my application name (agvanilla), paying attention to case.

I also changed an erroneous line at the top of class.skeletoncontroller.php from:

$this->Uses = array('Form');

to:

public $Uses = array('Database', 'DiscussionModel', 'Form');

...to mimic the a similar line at the top of the /applications/vanilla/class.discussionscontroller.php file

When I navigate to http://< ip >/agvanilla/homepage/index.php, I get:

[begin]
Page Not Found
The page you were looking for could not be found.
[end]

If I add var_dump calls to trace the code in class.agvanillacontroller.php, the code in its __construct() and Initialize() function is clearly being executed through to the end of each function.

Help?

Best Answers

  • edited April 2012 Accepted Answer

    I finally figured out what was going on. Here's how the file structure needs to be:

    After copying the skeleton application and renaming all references to 'skeleton' to whatever the new controller will be known as ('agvanilla' in this situation) -- paying attention to case -- to be able to go to any of the following eqiuvalent URLs:

    http://&lt;ip&gt;/agvanilla/

    http://&lt;ip&gt;/agvanilla/index

    http://&lt;ip&gt;/agvanilla/index/

    http://&lt;ip&gt;/agvanilla/index.php

    one must create an index method in the class.agvanillacontroller.php:

       public function index() {
           $this-&gt;Render();
       }
    

    and then create the following file:

    applications/agvanilla/views/agvanilla/index.php

    Fill that index.php with whatever HTML you'd like.

    Now navigate to one of those URLs above. Voila, it works!

  • peregrineperegrine MVP
    Accepted Answer

    you're the man.

    I may not provide the completed solution you might desire, but I do try to provide honest suggestions to help you solve your issue.

    philAG
  • hbfhbf wiki guy? MVP
    Accepted Answer

    Nice simple article on creating an application. Very cool. I may have to try my hand at that. Thanks.

    philAG

Answers

  • UnderDogUnderDog Moderator

    philAG said:
    When I navigate to http://< ip >/agvanilla/homepage/index.php, I get:
    [begin]
    Page Not Found
    The page you were looking for could not be found.
    [end]

    I've never written a new application for Vanilla, so I can only help you think in the right direction.

    Maybe, just maybe the problem has to do with routing, but I'm not sure. Let's focus on another thing first.

    Before you get the, let's call it 404 error, do you see in which code block the 404 error is generated? You said you did a var_dump(backtrace), can you post that backtrace or will it reveal too much of the code you do not want to reveal?

    Did you doublecheck the .htaccess file to reflect your IP address instead of the hostname?

    philAG
  • edited April 2012

    UnderDog said:
    I've never written a new application for Vanilla, so I can only help you think in the right direction.

    Maybe, just maybe the problem has to do with routing, but I'm not sure. Let's focus on another thing first.

    Before you get the, let's call it 404 error, do you see in which code block the 404 error is generated? You said you did a var_dump(backtrace), can you post that backtrace or will it reveal too much of the code you do not want to reveal?

    Results of debug_print_backtrace() in the :

    &lt;a href="/search?Search=%230&amp;amp;Mode=like"&gt;#0&lt;/a&gt; AgvanillaController-&gt;__construct() called at [/media/sf_vanilla/library/core/class.dispatcher.php:237] &lt;a href="/search?Search=%231&amp;amp;Mode=like"&gt;#1&lt;/a&gt; Gdn_Dispatcher-&gt;Dispatch() called at [/media/sf_vanilla/index.php:53] 
    
    &lt;a href="/search?Search=%230&amp;amp;Mode=like"&gt;#0&lt;/a&gt; AgvanillaController-&gt;Initialize() called at [/media/sf_vanilla/library/core/class.dispatcher.php:304] &lt;a href="/search?Search=%231&amp;amp;Mode=like"&gt;#1&lt;/a&gt; Gdn_Dispatcher-&gt;Dispatch() called at [/media/sf_vanilla/index.php:53] 
    

    No code executes in the agvanilla/controllers/homepage.php file, nor in the agvanilla/views/homepage/index.php file

    >

    Did you doublecheck the .htaccess file to reflect your IP address instead of the hostname?

    I'm using the default .htaccess file:

    # Original
    # If you modify this file then change the above line to: # Modified
    &lt;IfModule mod_rewrite.c&gt;
       RewriteEngine On
       # Certain hosts may require the following line.
       # If vanilla is in a subfolder then you need to specify it after the /. 
       # (ex. You put Vanilla in /forum so change the next line to: RewriteBase /forum)
       # RewriteBase /
       RewriteCond %{REQUEST_FILENAME} !-d
       RewriteCond %{REQUEST_FILENAME} !-f
       RewriteRule ^(.*)$ index.php\?p=$1 [QSA,L]
    &lt;/IfModule&gt;
    
  • peregrineperegrine MVP
    edited April 2012

    Before you wrote your application and modified various programs, what was the exact url that took you to the discussions page and did it work?

    The reason I ask, when i added an application, i just added it to the menu options
    it may not be the correct way but this is what I did
    I wrote a plugin and put this inside it.

    public function Base_Render_Before($Sender) {
          // Add "Application" to menu
          $Session = Gdn::Session();
        if ($Sender-&gt;Menu) {  
             $Sender-&gt;Menu-&gt;AddLink('MypluginAPP', T('My Application'), 'http://myhost.com/vanilla/myapplication.php');
    
               }
       } // end base render
    

    on second thought mine just read some rss feeds and didn't really interact with the vanilla database per se other than to get some feeds, so it might not work for you.

    I may not provide the completed solution you might desire, but I do try to provide honest suggestions to help you solve your issue.

    philAG
  • edited April 2012

    peregrine said:
    Before you wrote your application and modified various programs, what was the exact url that took you to the discussions page and did it work?

    If I just go to: http://&lt;ip&gt;/

    It takes me to the discussions front page.

  • edited April 2012

    UnderDog said:

    philAG said:
    Results of debug_print_backtrace() in the :

    Can you do exactly the same, but then for the 404 error page, please :-)

    Ok:

    &lt;a href="/search?Search=%230&amp;amp;Mode=like"&gt;#0&lt;/a&gt; Gdn_Dispatcher-&gt;Dispatch() called at [/media/sf_vanilla/index.php:53]
    

    That's at the line just before:

                Gdn::Request()-&gt;WithRoute('Default404');
                return $this-&gt;Dispatch();
    

    in class.dispatcher.php (line 329)

  • UnderDogUnderDog Moderator
    edited April 2012

    Aah, we're getting somewhere. This is for later moment to look at:

    if (!$PluginManagerHasReplacementMethod && ($this->_ControllerMethod == '' || !method_exists($Controller, $ControllerMethod))) {
    **some code**
    } else {
    Gdn::Request()->WithRoute('Default404');
    return $this->Dispatch();
    }
    

    So what I usually do is figure out why that top statement isn't 'active' and therefore the code generates a 404 error. It means looking at the $PluginManagerHasReplacementMethod variable, the _ControllerMethod variable, etc, etc

    If you have time, look at those variables using your var_dump method (which is great). I'll look at it also at my next opportunity

    philAG
  • UnderDog said:
    So what I usually do is figure out why that top statement isn't 'active' and therefore the code generates a 404 error. It means looking at the $PluginManagerHasReplacementMethod variable, the _ControllerMethod variable, etc, etc

    If you have time, look at those variables using your var_dump method (which is great). I'll look at it also at my next opportunity

    Yep, that's where I'm digging right now :)

  • edited April 2012 Accepted Answer

    I finally figured out what was going on. Here's how the file structure needs to be:

    After copying the skeleton application and renaming all references to 'skeleton' to whatever the new controller will be known as ('agvanilla' in this situation) -- paying attention to case -- to be able to go to any of the following eqiuvalent URLs:

    http://&lt;ip&gt;/agvanilla/

    http://&lt;ip&gt;/agvanilla/index

    http://&lt;ip&gt;/agvanilla/index/

    http://&lt;ip&gt;/agvanilla/index.php

    one must create an index method in the class.agvanillacontroller.php:

       public function index() {
           $this-&gt;Render();
       }
    

    and then create the following file:

    applications/agvanilla/views/agvanilla/index.php

    Fill that index.php with whatever HTML you'd like.

    Now navigate to one of those URLs above. Voila, it works!

  • peregrineperegrine MVP
    edited April 2012

    thanks nice overview

    so you created

    applications/agvanilla

    Sounds like you know what you are doing it would be great if you put an annotated version in the vanillawiki, if it is not too proprietary or just put in some stubs for the application code. It would probably be very helpful.

    http://vanillawiki.homebrewforums.net/index.php/Main_Page/

    @philAG

    I may not provide the completed solution you might desire, but I do try to provide honest suggestions to help you solve your issue.

    UnderDoghbfphilAG
  • Done: http://vanillawiki.homebrewforums.net/index.php/Hello_World_Application

    peregrine said:
    thanks nice overview

    so you created

    applications/agvanilla

    Sounds like you know what you are doing it would be great if you put an annotated version in the vanillawiki, if it is not too proprietary or just put in some stubs for the application code. It would probably be very helpful.

    http://vanillawiki.homebrewforums.net/index.php/Main_Page/

    @philAG

    peregrineleafmonsterUnderDog
  • peregrineperegrine MVP
    Accepted Answer

    you're the man.

    I may not provide the completed solution you might desire, but I do try to provide honest suggestions to help you solve your issue.

    philAG
  • hbfhbf wiki guy? MVP
    Accepted Answer

    Nice simple article on creating an application. Very cool. I may have to try my hand at that. Thanks.

    philAG
  • UnderDogUnderDog Moderator

    Thanks for the article. I have a question:

    One of those files you'll be renaming is class.skeletoncontroller.php -- it'll now be class.myappcontroller.php. In that file, add an index method

    Does that mean that the skeleton application lacks a method in the controller called index() ? Wow, so the skeleton application wasn't complete!

    philAG
  • x00x00 MVP
    edited April 2012

    Yep basic idea of model controller view is every view has an associated controller method.

    By that I don't mean helper views, which are included by other views.

    grep is your friend.

    philAG
  • edited April 2012

    UnderDog said:
    Thanks for the article. I have a question:

    One of those files you'll be renaming is class.skeletoncontroller.php -- it'll now be class.myappcontroller.php. In that file, add an index method

    Does that mean that the skeleton application lacks a method in the controller called index() ? Wow, so the skeleton application wasn't complete!

    Not only is the skeleton application not complete, it has a bug in the code which causes PHP to throw an error. You have to either comment out this erroneous line at the top of class.skeletoncontroller.php :

    $this-&gt;Uses = array('Form');

    Or you have to change it; I used this line from the main Vanilla application controller:

    public $Uses = array('Database', 'DiscussionModel', 'Form');

    @hbf -- watch out for that...

  • As I answered my own question, how should I proceed with all of the other posts in this topic? Am I doing the correct thing in liking, but rejecting each of them?

  • I would only reject if it was explicitly unhelpful.

    grep is your friend.

    philAG
  • peregrineperegrine MVP
    edited April 2012

    I thought you had to choose either reject or accept. And choose reject if the message doesn't answer the question. Confusion here. I think if you answer your own question the moderator will mark it as solved.

    my concept is you click like if it seems like the person put some effort into making a response and it kinda helped you on your way.

    I may not provide the completed solution you might desire, but I do try to provide honest suggestions to help you solve your issue.

    philAG
  • UnderDogUnderDog Moderator

    I wouldn't reject an answer until, like x00 says it's explicitly unhelpful. It keeps popping up that annoying message that I should accept or reject an answer, but I take that for granted.

    The like is exactly like peregrine says, if it seems like the user made an effort, click the like button.

    Here's a (small) thread about the 'like etiquette' : http://vanillaforums.org/discussion/19424/like-etiquette we could put our thoughts in there...

    I'll accept your answer for you, if you like, send me a PM or tell me here in the thread please :-)

    philAG
  • @UnderDog: yes, please accept this answer: http://vanillaforums.org/discussion/comment/157786#Comment_157786

    My thing is that Vanilla keeps popping up a Growl-ish box saying "you must accept or reject comments". I answered my question, I've liked the helpful comments, please ask Vanilla to stop bugging me :)

    UnderDog
  • peregrineperegrine MVP
    edited April 2012

    I remain in your camp philAG
    I think if you solve your own problem, I just click reject, and be done with it, if you want it to remain a "question" or if you want to it be an answer "just pick a random message or the last message and click accept. I think this is all a logic flaw - we need a solve button for a user that solves there own problem and dismisses the reject and accept and marks the question answered. if you ask me, but you didn't :).

    I may not provide the completed solution you might desire, but I do try to provide honest suggestions to help you solve your issue.

    philAG
  • UnderDogUnderDog Moderator

    peregrine said:
    I think this is all a logic flaw - we need a solve button for a user that solves there own problem and dismisses the reject and accept and marks the question answered.

    In the meantime, feel free to send me PM's asking to accept specific comments as answered, as Phil just did. I don't mind, besides, I can mark the topic title as 'Solved' while I'm accepting the answer anyways.

    peregrinephilAG
Sign In or Register to comment.