Closed eothein closed 5 years ago
Thanks for the detailed report, now i can see what you are doing.
$url = Url::toRoute(['/inschrijvingfrontend/toernooi/index',"toernooi" => $toernooi->id]);
I assume its a foreach? So your main intention is to have pages generated from the module?
inschrijvingfrontend
module?=> https://luya.io/guide/app-module-urlrules
Dear @nadar
The reason for is that I want to generate a link to a page in the module (i.e. a page representing a tournament). I have a controller in the front-end which takes the $toernooi
as id and then generates the page for that tournament.
I have not added url rules for the inschrijvingsfrontend
module. Is this necessary when generating a module?
Ok so I added the following rule:
public $urlRules = [
['pattern' => 'bp-detail', 'route' => 'inschrijvingfrontend/toernooi/index'],
];
And this does the trick.
Although it is not clear to me why this must be done to get the modules working. I checked the Yii2 documentation for modules which states:
Like accessing controllers in an application, routes are used to address controllers in a module. A route for a controller within a module must begin with the module ID followed by the controller ID and action ID. For example, if an application uses a module named forum, then the route forum/post/index would represent the index action of the post controller in the module.
So I thought that the following code would render the correct link (which it did without the addition of the contact_form module).
$url = Url::toRoute(['/inschrijvingfrontend/toernooi/index',"toernooi" => $toernooi->id]);
The problem is that you are using the LUYA CMS Module and the cms needs to catch ALL PATHS in order to work, for example we need to catch /xyz/y/z and pass it to the cms in order to display the correct page. So we have to differ between cms and module routes, therefore in this case an url rules is needed. So i can close the issue?
Hello @nadar , thanks for the explanation. I will indeed close the issue.
Maybe a change in the documentation/guide would be handy: i.e. when using own modules, adding an URL rule is necessary?
The url rule is only required if you DONT add the module as module-page or with module-block inside a page.
This is unclear to me.
I added both the contactModule and the inschrijvingsModule as a page.
When I delete the urlRoute e.g.
public $urlRules = [
//['pattern' => 'bp-detail', 'route' => 'inschrijvingfrontend/toernooi/index'],
];
then
$url = Url::toRoute(['/inschrijvingfrontend/toernooi/index',
"toernooi" => $toernooi->id]);
rendered in the main.php
file, when accessing http://beachpolo.test/contact
renders the url http://beachpolo.test/contact/toernooi/index?toernooi=3
Which is not correct. Should be http://beachpolo.test/inschrijvingfrontend/toernooi/index?toernooi=1
What am I not getting?
try: toModuleRoute from cms url helper
Ok, so this does the trick. Well let me correct my tip for the documentation. Using the correct Url class, i.e. use luya\cms\helpers\Url;
;)
What steps will reproduce the problem?
Generate links in the
views/layouts/main.php
file as follows for my own module, which I use in the navbarGenerate other menu-items in the navbar as follows:
What is the expected result?
Correct url form's for the custom module and the contact module, e.g.
http://beachpolo.test/inschrijvingfrontend/toernooi/index?toernooi=1
http://beachpolo.test/contact
And this from any page.
What do you get instead? (A Screenshot can help us a lot!)
starting when first accessing a page in own module or main page:
http://beachpolo.test/inschrijvingfrontend/toernooi/index?toernooi=1
- okstarting when first accessing a page in own module or main page: contact form page:
http://beachpolo.test/contact
okonce I am on the contact page (which is displayed correctly), the url's for my own module are generated as follows:
http://beachpolo.test/contact/toernooi/index?toernooi=1
So it tries to contact the controller from the contact module, instead of the controller of the inschrijvingsmodule and hence the url is malformed.
LUYA Check ouput (run this script and post the result: [luyacheck.php]1: [in_array('mod_rewrite', apache_get_modules())] true
2: [ini_get('short_open_tag')] '' 3: [ini_get('error_reporting')] '22527' 4: [phpversion()] '7.1.23' 5: [php_ini_loaded_file()] '/etc/php.ini' 6: [php_sapi_name()] 'apache2handler' 7: [isset($_SERVER['SERVER_SOFTWARE']) ? $_SERVER['SERVER_SOFTWARE'] : unknown] 'Apache/2.4.34 (Unix) PHP/7.1.23'
Additional infos