Take the 2-minute tour ×
Craft CMS Stack Exchange is a question and answer site for administrators, end users, developers and designers for Craft CMS. It's 100% free, no registration required.

I'm having trouble registering a CP route. What I have is a "working" SiteAdministrator_UserController.php (other form save actions already work through this controller, so its functional). Inside the controller I have a function :

public function actionCurrent()
{
    die ('Works!');
}

In my Plugin I have the following:

public function registerCpRoutes()
{
    return array(
        'siteadministator/currentusers' => array('action' => 'siteAdministrator/user/current')
    );
}

trying the uri http://cms.craft.dev/admin/siteadministrator/currentusers

Craft says its a 404.

What am I doing wrong and/or is there a way to debug this?

Thanks in advance

share|improve this question
    
Can you post your entire controller code? Minus any details you do not want to share of course. –  Jason McCallister Jul 27 at 21:01

3 Answers 3

Based on your code excerpts, things look good. I've encountered issues with spelling and caps when referencing controllers and templates within my controllers...so pay close attention to them.

I would suggest referencing the 'Cocktail Recipes' sample plugin: https://github.com/adrianmacneil/cocktailrecipes as it contains an example of what you're trying to do.

share|improve this answer
    
For future reference, that plugin is outdated and has been forked to this repo with updates: github.com/seandelaney/cocktailrecipes –  Jason McCallister Jul 28 at 3:03

Dumb ass typo : "siteadministator" instead of siteadministRator sigh ... Sorry for taking up bytes.

Working method now is:

public function hookRegisterCpRoutes()
{
    return array(
        'siteadministrator/currentusers' => array('action' => 'siteAdministrator/user/current'),
    );
}
share|improve this answer

The documentation on Craft's website covers registering control panel routes here:

Posting to Controller Actions

Troubleshooting

According to the documentation your route is setup correctly. I have had an experience where a route would not register. I took the following steps to troubleshoot:

  1. Uninstalled the plugin
  2. Reinstalled the plugin
  3. Checked spelling on the controller and the main plugins class 'registerCpRoutes' method.

However, if you are at a point where uninstalling is out of the question, I would again check for spelling and make sure there are no typos or missing brackets in the controller and main plugin class. In my case, I found a small typo and that corrected my issue.

Debugging/Linters

Depending on what text editor you are using, you might also want to look at using a Linter. A linter for PHP essentially runs the command line php -l which will check the syntax on your PHP file.

I use Atom on a daily basis and use the Atom Linter package. However, I know Sublime has a Linter package as well but I am not familiar with that one.

Helper Plugins

You may also want to look into installing this plugin from Matt Stauffer: Plugin Dev Helpers. This will allow you to use the 'die and dump' helper that exists in the Laravel framework. Essentially allowing you to use dd($anyVariableName), which will dump and die but allows you to pass variables to the output.

share|improve this answer
    
Computer says no...:( –  pythic Jul 27 at 20:48
    
Yeah, you are right. Just looked at some of my code and realized I was wrong. Looking into it now. –  Jason McCallister Jul 27 at 20:50
    
I updated the answer, let me know if I can help. –  Jason McCallister Jul 27 at 21:10
    
I'll try the above tomorrow, its getting kind of late over here. I have a client waiting in the morning :) Thank you so far –  pythic Jul 27 at 21:15
1  
Thanks for all the tips above. What I did notice is that in the cocktailrecipe example the registerCpRoutes method is not used, he uses hookRegisterCpRoutes. Not sure that the difference is but they both get called by the framework. Anyway that didn't solve my problem... What did solve it is that after 14 hrs of coding I made a typo, its hiding in plain sight... "siteadministator" instead of siteadministRator sigh ... Sorry for taking up bytes. –  pythic Jul 28 at 18:42

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.