Moving from Tools to Routes
Permalink
I'm trying to map a route to a class I used for a tool in 5.6. How to do that exactly? I'm using this:
But accessing /index.php/mypackage/campaign gives me this error message:
Note that this isn't a real c5 controller since it was previously a tool, I'd like to use it anyway though, and thought it could be done with the new Routing. Can anyone shed light on how to do this?
Route::register('/mypackage/campaign', '\Concrete\Package\Mypackage\Controllers\CampaignController');
But accessing /index.php/mypackage/campaign gives me this error message:
Class 'Concrete\Package\Mypackage\Controllers\MypackageController' not found
Note that this isn't a real c5 controller since it was previously a tool, I'd like to use it anyway though, and thought it could be done with the new Routing. Can anyone shed light on how to do this?
Since a tools file was pretty much just an include you could probably just do something like this in the short term.
Ah, nice and simple, thanks! (And turning on full error display helped me further, my bad.)
While I'm at it, do you know how the namespace routing works with the core classes? I don't understand exactly how you can "use [Any core class];" anywhere and it works?
While I'm at it, do you know how the namespace routing works with the core classes? I don't understand exactly how you can "use [Any core class];" anywhere and it works?
concrete5.7 uses PSR-4(slightly modified) for autoloading. Basically that means that you can line up the classes you see with the /concrete/src/ directory being '\Concrete'
So
Would correspond with the file
But since concrete5.7 also uses class aliases for many of the core classes you can also just use
To see which classes have aliases assigned to them you can look here
https://github.com/concrete5/concrete5-5.7.0/blob/develop/web/concre...
Both of the above `use` statements will work, the shorthand aliases are just there for simplicity and convince.
So
use Concrete\User\User;
Would correspond with the file
/concrete/src/User/User.php
But since concrete5.7 also uses class aliases for many of the core classes you can also just use
use User;
To see which classes have aliases assigned to them you can look here
https://github.com/concrete5/concrete5-5.7.0/blob/develop/web/concre...
Both of the above `use` statements will work, the shorthand aliases are just there for simplicity and convince.
I'm in the same boat, but don't quite follow how this needs to be setup. I previously could access tools within my package via /tools/packages/{package-name}/{tool-name}. As a matter of fact, this is still the URL that is generated by C5 when using:
Yet, when I access this URL in 5.7, I just get a blank page. My tool consists of nothing but
Am I missing something? If I need to register a route, where do I do so within the package?
<?php echo Loader::helper('concrete/urls')->getToolsURL('{tool-name}','{package-name}');?>
Yet, when I access this URL in 5.7, I just get a blank page. My tool consists of nothing but
<?php echo 'Hello world.';
Am I missing something? If I need to register a route, where do I do so within the package?
I've found some helpful information in the following threads:
http://www.concrete5.org/community/forums/5-7-discussion/a-few-ques...
http://www.concrete5.org/community/forums/5-7-discussion/implementi...
http://www.concrete5.org/community/forums/5-7-discussion/a-few-ques...
http://www.concrete5.org/community/forums/5-7-discussion/implementi...
Ah great, one of the replies there looks like a good way to use controllers:http://www.concrete5.org/community/forums/5-7-discussion/a-few-ques...
Yes you need to define routes for this to work. A nice place to do that is in the package controller, since it is instantiated automatically when the package is installed. Something like this:
The above code will display viewName.php which is supposed to be in the "elements" directory in your package.
Since you'll request this as a URL, it will probably be nicer to use a concrete controller instead, creating it inside the anonymous function. Haven't got an example how to do that, it should be much easier to do with 5.7 than before though.
EDIT: This looks like a good way to do it:http://www.concrete5.org/community/forums/5-7-discussion/a-few-ques...
namespace Concrete\Package\YourPackage; use Package; use Route; use View; class Controller extends Package { // ... further down ... public function on_start() { Route::register('/some/nice/url', function() { View::element('viewName', null, 'your_package'); }); } }
The above code will display viewName.php which is supposed to be in the "elements" directory in your package.
Since you'll request this as a URL, it will probably be nicer to use a concrete controller instead, creating it inside the anonymous function. Haven't got an example how to do that, it should be much easier to do with 5.7 than before though.
EDIT: This looks like a good way to do it:http://www.concrete5.org/community/forums/5-7-discussion/a-few-ques...