Unable to access module. 404

+
0
-

Hi am creating a simple blog module using the documentation for modules at https://doc.nette.org/…n/presenters

I have the file app/BlogModule/presenters/BlogPresenter.php which contains

<?php

namespace BlogModule;

class BlogPresenter extends Nette\Application\UI\Presenter
{
// …
}

However, I am getting a 404
Nette\Application\BadRequestException #404
Cannot load presenter ‘Blog’, class ‘App\Presenters\BlogPresenter’ was not found

What, or how many things, am I doing wrong?

Does the BlogModule need to be ‘registered’ in config or something?
A custom route?
htaccess issue?

Thanks Kev

CZechBoY
Member | 3608
+
+1
-

What url are you accessing?
Your namespace should be app\BlogModule\presenters. Then the access url should be /blog/blog.

Petr Parolek
Member | 455
+
0
-

Hi,

you have to use namespace App\BlogModule\Presenters or change mapping in config.neon

+
0
-

Thanks for you replies.

The issue still persists when accessing the /blog/blog or even /blog

?php

namespace App\BlogModule\Presenters;

class BlogPresenter extends Nette\Application\UI\Presenter
{
// …
}

Is there something which needs to be present in config to enable modules?
The presenter is located in app/BlogModule/presenters/BlogPresenter.php

Error:
Nette\Application\BadRequestException #404
Cannot load presenter ‘Blog’, class ‘App\Presenters\BlogPresenter’ was not found.

CZechBoY
Member | 3608
+
0
-

I wrote bad url, by default it is /blog.blog/default. You should create link for that in menu or something…

+
0
-

Ahh thanks.
This fixes the error of Blog class not found, however, there is no route.
Nette\Application\BadRequestException #404
No route for HTTP request.

Do I need to create a custom route?

Thanks
Kevin

CZechBoY
Member | 3608
+
0
-

hm… can you send router + config? :D

+
0
-

This is my config.neon file
parameters:

application:
errorPresenter: Error
mapping:
*: App*Module\Presenters*Presenter

session:
expiration: 14 days

services:
router: App\RouterFactory::createRouter

This is the router:
<?php

namespace App;

use Nette;
use Nette\Application\Routers\Route;
use Nette\Application\Routers\RouteList;

final class RouterFactory
{
use Nette\StaticClass;

/**
* @return Nette\Application\IRouter
*/
public static function createRouter()
{
$router = new RouteList;
$router[] = new Route(‘<presenter>/<action>[/<id>]’, ‘Homepage:default’);
return $router;
 }
}

I should add that this is an install simply using composer.

Last edited by kevin.waterson@gmail.com (2019-03-11 10:25)

CZechBoY
Member | 3608
+
0
-

mapping should be

application:
    mapping:
            *: App\*Module\Presenters\*Presenter

btw please use syntax highlighter for codes /--php + code + \-- and /--neon + config + \--

+
0
-

Problem still exists.

URL is /blog:blog/default

Nette\Application\BadRequestException #404
No route for HTTP request.

My config now looks like this:

parameters:


application:
        mapping:
                *: App\*Module\Presenters\*Presenter


session:
        expiration: 14 days


services:
        router: App\RouterFactory::createRouter

I am guessing I am doing something fundamentally wrong or immoral.

Kevin

Last edited by kevin.waterson@gmail.com (2019-03-11 23:41)

CZechBoY
Member | 3608
+
0
-

There is dot ., not colon : in url.

+
0
-

OK, noted.. now we have come full circle ..
/blog.blog/default

Nette\Application\InvalidPresenterException
Cannot load presenter 'Blog:Blog', class 'App\BlogModule\presenters\BlogPresenter' was not found.
parameters:


application:
        mapping:
                *: App\*Module\presenters\*Presenter


session:
        expiration: 14 days


services:
        router: App\RouterFactory::createRouter

The path to my presenter is: app/BlogModule/presenters/BlogPresenter.php

My presenter looks like this:

<?php

namespace App\BlogModule\Presenters;

class BlogPresenter extends Nette\Application\UI\Presenter
{
        /** @var Nette\Database\Context */
        private $database;

        public function __construct(Nette\Database\Context $database)
        {
                $this->database = $database;
        }

        public function renderDefault()
        {
                $this->template->posts = $this->database->table('posts')
                        ->order('created_at DESC')
                        ->limit(5);
        }


        public function renderShow($id)
        {
                // get data model and pass to template
                // $this->template->blog = $this->blogRepository->getBlog($id);
        }
}
CZechBoY
Member | 3608
+
+1
-

There should be big first letter P in Presenters (as in namespace).

this shoule be still ok

application:
    mapping:
            *: App\*Module\Presenters\*Presenter

or if you want lowercase

application:
    mapping:
            *: App\*Module\presenters\*Presenter

Last edited by CZechBoY (2019-03-12 01:32)

+
0
-

When I change ‘presenters’ to Presenters, the only thing which changes is the error message.

Nette\Application\BadRequestException #404
Cannot load presenter 'Blog:Blog', class 'App\BlogModule\Presenters\BlogPresenter' was not found
Nette\Application\BadRequestException #404
Cannot load presenter 'Blog:Blog', class 'App\BlogModule\presenters\BlogPresenter' was not found

However, when the App is changed to app, we get past the error

application:
    mapping:
            *: app\*Module\Presenters\*Presenter

And this presents a new error…

Fatal Error
Class 'App\BlogModule\Presenters\Nette\Application\UI\Presenter' not found

to fix this, we need to have access to Nette namespace, so in the BlogPresenter class..

<?php

namespace App\BlogModule\Presenters;

// alias Nette for use when extending
use Nette;

class BlogPresenter extends Nette\Application\UI\Presenter
{
  // ----
}

Then, when I change the filesystem to have app/BlogModule/templates/Blog/default.latte it works. (this will be a new thread)

Thanks for help resolving this for a newbie.

Kev