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

Controller inside a plugin suddenly not recognized

GO3LINGO3LIN New
edited October 2015 in Vanilla 2.0 - 2.8

Hello,

I have created some controllers inside a plugin, that worked perfectly until I have made some changes (created some other plugins). The controller page shows the error "Page not found" however I haven't touched anything in the plugin where the controllers are defined. I am actually stuck with this problem, and I don't get any debug information. The controllers files are actually charged because when I put a die('controller'); and I go to the wanted controller the page prints the string inside the die, but it seems like it doesn't run any of the controllers methode nor the initialize nor index methods. That's a very strange behaviour. I have also cleared the cache after the changes I had made, maybe something in the cache went wrong ?

Thanks for your help

«1

Comments

  • Options
    vrijvlindervrijvlinder Papillon-Sauvage MVP

    What do you mean by controllers, are they views ? Please post code , not sure what you mean . Please post an example

  • Options
    peregrineperegrine MVP
    edited October 2015

    maybe its a rhetorical question. =) or he's looking for a person with x-ray vision.

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

  • Options

    @vrijvlinder said:
    What do you mean by controllers, are they views ? Please post code , not sure what you mean . Please post an example

    If you are not sure what controllers are I wouldn't try to answer the question.

    I agree with peregrine Op needs to provide work.

    grep is your friend.

  • Options
    R_JR_J Ex-Fanboy Munich Admin

    Have you created any routes? Maybe they are set to the wrong target.

    Last time I noticed a "strange behavior" was when I duplicated a plugin directory and left some files unaltered.

    But I must agree that "something strange is happening" is hard to debug ;) If you could provide just a little bit more details, we could be more helpful.

  • Options
    vrijvlindervrijvlinder Papillon-Sauvage MVP

    @x00 said:
    If you are not sure what controllers are I wouldn't try to answer the question.

    I know what controllers are ffs!! Do you ? The OP is the one who is confused and that is why I asked for more info...

  • Options

    @vrijvlinder said:
    I know what controllers are ffs!! Do you ? The OP is the one who is confused and that is why I asked for more info...

    You sometimes offer answers to questions you don't really know about this can cause confusion, especially if they are encouraged to shotgun debug.

    A controller is not a view and views don't have methods.

    grep is your friend.

  • Options
    peregrineperegrine MVP
    edited October 2015

    In any event the op is not too concerned otherwise they would have posted some code as Vrijvlinder, you, and I alluded too. So no reason for anyone to get agitated.

    Maybe V was alluding to a method in the controller that set a view and attempted to render it.

    Unless the OP provides code and/or more info, one can probably say r_j has the best advice that can be given to the OP

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

  • Options

    Hi, I'm sorry I was very busy yesteday. So to clarify my problem: I created a controller inside of a plugin, vanilla charges automatically my controller file: here's the folder hierarchie of my plugin:

    I know that the controller files are included because when I write a die('hello'); in the beginning of those files It actually shows the 'hello' string. But when I go to the url : /?p=/documents for example it doesn't recognize the controller and I get a page not found error. Here's a sample code of the documentsController :

    <?php
    class DocumentsController extends Gdn_Controller {

    public function Initialize() {
        // Set up head.
        $this->Head = new HeadModule($this);
    
        // Add JS files.
        $this->AddJsFile('jquery.js');
        $this->AddJsFile('jquery.livequery.js');
        $this->AddJsFile('jquery.form.js');
        $this->AddJsFile('jquery.popup.js');
        $this->AddJsFile('jquery.gardenhandleajaxform.js');
        $this->AddJsFile('jquery.autogrow.js');
        $this->AddJsFile('global.js');
        $this->AddJsFile('articles.js');
    
        // Add CSS files.
        $this->AddCssFile('style.css');
        $this->AddCssFile('dpl.css');
    
        // Add modules.
        $this->AddModule('GuestModule');
        $this->AddModule('SignedInModule');
        $this->AddModule('DiscussionsModule');
        $this->AddModule('RecentActivityModule');
        $this->AddModule('DiscussionFilterModule');
        $this->AddModule('CategoriesModule');
        $this->AddModule('BookmarkedModule');
        $this->AddModule('TagModule');
    
        parent::Initialize();
    }
    
    
    public function Index(){
        $this->permission('Garden.SignIn.Allow');
        Gdn_Theme::section('DiscussionList');
    
        $Session = Gdn::session();
        // Set criteria & get discussions data
        list($Offset, $Limit) = offsetLimit($Page, c('Vanilla.Discussions.PerPage', 30));
        $Wheres = array('d.InsertUserID' => $Session->UserID);
        $DiscussionModel = new DiscussionModel();
        $docDiscussions = Gdn::sql()
            ->select('d.*')
            ->from('Discussion d')
            ->join('Media m', 'd.DiscussionID=m.ForeignID')
            //->join('')
            ->where('m.InsertUserID', $Session->UserID)
            ->get();
        $this->DiscussionData = $DiscussionModel->get($Offset, $Limit, $Wheres);
        CategoryModel::JoinCategories($docDiscussions);
        $userModel = new UserModel();
        $userModel->joinUsers($docDiscussions, array('InsertUserID', 'LastCommentUserID'));
        // Hack to replace the column with the appropriate fields
        foreach($docDiscussions as &$disc){
            $disc->Url = Gdn::request()->url('/discussion/'.$disc->DiscussionID.'/'.Gdn_Format::Url($disc->Name), true);
            $disc->FirstDate = $disc->DateLastComment;
            $disc->LastDate = $disc->DateLastComment;
            $disc->FirstName = $disc->InsertName;
            $disc->LastName = $disc->LastCommentName;
        }
        $this->DiscussionData = $docDiscussions;
    
        $this->setData('Discussions', $this->DiscussionData);
        $this->View = $this->fetchViewLocation('index', 'Discussions', 'vanilla');
        if (c('Vanilla.Discussions.Layout') === 'table') {
            $this->View = $this->fetchViewLocation('table', 'Discussions', 'vanilla');
        }
    
    
    
        // Render view
        $this->setData('Title', t('Documents'));
        $this->setData('Breadcrumbs', array(array('Name' => t('Documents'), 'Url' => '/documents')));
        $this->render();
    
    
    }
    

    }

  • Options
    vrijvlindervrijvlinder Papillon-Sauvage MVP

    But when I go to the url : /?p=/documents for example it doesn't recognize the controller and I get a page not found error.

    Thanks for the code and further explanation. I suspect your issue has to do with ReWriteURL and the htaccess file being misconfigured.

    Please check that ReWrite URL is True in the config.php and also make sure the htaccess file does not have ReWriteBase commented out and reflects your correct directory or subdirectory...

  • Options
    peregrineperegrine MVP
    edited October 2015

    since you said: but it seems like it doesn't run any of the controllers methode nor the initialize nor index methods.

    If you still have an issue....

    when you put a var_dump("line 28") at line 28 and
    when you put a var_dump("line 62") at line 62 and
    and a var_dump($this->View) at line 69.
    and a die("line 70") at line 70 in the code above.

    what do you see?

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

  • Options

    @vrijvlinder said:
    Please check that ReWrite URL is True in the config.php and also make sure the htaccess file does not have ReWriteBase commented out and reflects your correct directory or subdirectory...

    Actually I don't have the RewriteUrl option in my config file. Do you mean the Pretty Url format? because I don't really need it. I don't have any htaccess file in the root of my application.

    @peregrine said:
    when you put a var_dump("line 28") at line 28 and
    when you put a var_dump("line 62") at line 62 and
    and a var_dump($this->View) at line 69.
    and a die("line 70") at line 70 in the code above.

    what do you see?

    I don't see anything (still page not found), I am able to see an output only if I write the debug code before the class declaration.

  • Options
    x00x00 MVP
    edited October 2015

    There is an hook base_afterControllerCreate_hander that you can use to confirm if any controller is created.

    you can check $sender->controller()

    grep is your friend.

  • Options
    GO3LINGO3LIN New
    edited October 2015

    Hi, I have put the hook in my plugin class, and when I went to the /?p=/documents page. I checked the $sender->controller() output is returning 'Home'. So what ? my controller is not recognized ?

    The really strange part in this bug is that the server where I am pushing the changes is working correctly. That's why I thought about a cache problem.

  • Options

    it may be rewrouted after not found so make sure you output in error log.

    grep is your friend.

  • Options

    Can you explain more what I should output because the $Sender->controller returned "Home" while it should be the documents controller

  • Options
    vrijvlindervrijvlinder Papillon-Sauvage MVP

    Usually 404 error has to do with htacess in some cases rewriteurl needs to be true or the link will not work properly . Same with update. If you don't try it you will not know if that is part of the issue or not.

  • Options
    peregrineperegrine MVP
    edited October 2015

    The really strange part in this bug is that the server where I am pushing the changes is working correctly. That's why I thought about a cache problem.

    So you are saying things work great on one server but not on another.

    after you check routing, disable plugin and re-enable plugin, and other suggestions, if you still have problem....

    Ensure you don't have some duplicate or test plugin that may be interfering on your test server (the other plugin does not have to be enabled to screw things up).

    you could start by zipping up other plugins on your test server and removing the folders from them from the plugins folder and testing this one alone.

    http://vanillaforums.org/discussion/comment/233540/#Comment_233540

    http://vanillaforums.org/discussion/26786/tutorial-how-to-enable-a-debug-log-and-collect-debugging-information


    I think you answered your own question in the beginning.

    if you are comparing to a server that plugin works vs. one that doesn't work, you need to look at the differences between the two. versions, plugins folder, themes, routes, rewriting, etc.

    I have created some controllers inside a plugin, that worked perfectly until I have made some changes (created some other plugins).

    if all you did was this. no vanilla upgrades that is (one can assume .htaccess has no impact).
    therefore one of the plugins has created issue.

    if you didn't modify plugin that worked once before. and you have disabled and re-enabled, one has to believe the other plugins are creating the conflict with your plugin.

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

  • Options

    Are you testing this on windows?

    I tried refactoring a plugin to use controllers a while ago but have given up on it, because it was very dodgy on windows. It would save the wrong path to the autoloader map, because backslashes were not recognized as directory separators.

    This should be fixed in 2.2 though (which you seem to be using):
    https://github.com/vanilla/vanilla/pull/2869

  • Options

    Looks like I forgot backporting this, so it is not in 2.2 yet.

    If you are using windows, could you apply this patch and check if it works?
    https://github.com/vanilla/vanilla/pull/3222/files

  • Options
    GO3LINGO3LIN New
    edited October 2015

    @peregrine : That's what I did, I compared the servers but the only thing that is different is that in the remote server I haven't sent the conflicting plugin. I might have a conflict in the PluginInfo variable. Compressing the other plugins, disabling and re-enabling didn't work.

    @Bleistivt : Yes the test server is on Windows, while the (production) one is on ubuntu. But it was working before I created that new plugin. I tried replacing the DS constant defined in the index.php from '/' to DIRECTORY_SEPARATOR, but that didn't work also I tried the patch with no results.

Sign In or Register to comment.