Please upgrade here. These earlier versions are no longer being updated and have security issues.
HackerOne users: Testing against this community violates our program's Terms of Service and will result in your bounty being denied.

[Solved] [Documentation] Need help writing an application

edited April 2012 in Vanilla 2.0 - 2.8

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 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://<ip>/agvanilla/

    http://<ip>/agvanilla/index

    http://<ip>/agvanilla/index/

    http://<ip>/agvanilla/index.php

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

       public function index() {
           $this->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
    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.

  • hbfhbf MVP
    Answer ✓

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

«1

Answers

  • philAG said:
    When I navigate to http://&lt; 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?

    There was an error rendering this rich post.

  • 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 :

    #0 AgvanillaController->__construct() called at [/media/sf_vanilla/library/core/class.dispatcher.php:237] #1 Gdn_Dispatcher->Dispatch() called at [/media/sf_vanilla/index.php:53] 
    
    #0 AgvanillaController->Initialize() called at [/media/sf_vanilla/library/core/class.dispatcher.php:304] #1 Gdn_Dispatcher->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
    <IfModule mod_rewrite.c>
       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]
    </IfModule>
    
  • 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->Menu) {  
             $Sender->Menu->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.

  • 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://<ip>/

    It takes me to the discussions front page.

  • philAG said:
    Results of debug_print_backtrace() in the :

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

    There was an error rendering this rich post.

  • 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:

    #0 Gdn_Dispatcher->Dispatch() called at [/media/sf_vanilla/index.php:53]
    

    That's at the line just before:

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

    in class.dispatcher.php (line 329)

  • UnderDogUnderDog MVP
    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

    There was an error rendering this rich post.

  • 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 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://<ip>/agvanilla/

    http://<ip>/agvanilla/index

    http://<ip>/agvanilla/index/

    http://<ip>/agvanilla/index.php

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

       public function index() {
           $this->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.

  • 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

  • peregrineperegrine MVP
    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.

  • hbfhbf MVP
    Answer ✓

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

  • 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!

    There was an error rendering this rich post.

  • 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.

  • 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->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.

  • 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.

  • 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 :-)

    There was an error rendering this rich post.

Sign In or Register to comment.