getherbert / herbert

The WordPress Plugin Framework:
http://getherbert.com/
632 stars 94 forks source link

Basic Routing Question #134

Open beatelite opened 8 years ago

beatelite commented 8 years ago

in my routes.php I have:

<?php namespace AR6SAASPlans;

/** @var \Herbert\Framework\Router $router */

$router->get([
    'as'   => 'test',
    'uri'  => '/test',
    'uses' => __NAMESPACE__ . '\Controllers\SignUpCtrl@showSignUp'
]);

In my SignUpCtrl.php in the Controllers folder, I have:

<?php namespace AR6SAASPlans\Controllers;

class SignUpCtrl {

    /**
     * Shows the signup form.
     *
     */
    public function showSignUp()
    {
        // $post = Post::find($id);
        // echo Helper::get('pluginName');

        return view('@AR6SAASPlans/signupview.twig');
    }
}

in my signupview.twig file I have

<h1>test</h1>

However, I when I visit mysite.com/test

I get a blank page (console says 500 error. )

If I use a closure like so:

$router->get([
    'as'   => 'simpleRoute',
    'uri'  => '/simple',
    'uses' => function()
    {
        return 'Hello World';
    }
]);

It works for me. What am I missing when I use a controller?

arippberger commented 8 years ago

@beatelite please check your error logs (or turn on error output in your php.ini) and report back. It's difficult to assess the problem without seeing the specific error.

beatelite commented 8 years ago

This is the error:

Fatal error: Uncaught exception 'ReflectionException' with message 'Class AR6SAASPlans\Controllers\SignUpCtrl does not exist' in /home/a6/Web/web/app/plugins/ar-saas-plans/vendor/illuminate/container/Container.php:734 Stack trace: #0 /home/atlas6/Web/web/app/plugins/ar-saas-plans/vendor/illuminate/container/Container.php(734): ReflectionClass->__construct('AR6SAASPlans\Co...') #1 /home/a6/Web/web/app/plugins/ar-saas-plans/vendor/illuminate/container/Container.php(629): Illuminate\Container\Container->build('AR6SAASPlans\Co...', Array) #2 /home/a6/Web/web/app/plugins/ar-saas-plans/vendor/getherbert/framework/Herbert/Framework/Application.php(974): Illuminate\Container\Container->make('AR6SAASPlans\Co...', Array) #3 /home/a6/Web/web/app/plugins/ar-saas-plans/vendor/illuminate/container/Container.php(602): Herbert\Framework\Application->make('AR6SAASPlans\Co...') #4 /home/a6/Web/web/app/plugins/ar-saas-plans/vendor/illuminate/container/Container.php(502): Illuminate\Container\Container->callClass('AR6SAAS in /home/a6/Web/web/app/plugins/ar-saas-plans/vendor/illuminate/container/Container.php on line 734

I checked to make sure all my syntax was correct and comparing everything to your docs, it does look like it is.

arippberger commented 8 years ago

@beatelite I believe this is a namespace error: you're trying to access the SignUpCtrl class but your autoloader can't find it. Could you try adding use AR6SAASPlans\Controllers\SignUpCtrl; at the top of your routes.php file (under the namespace declaration)?

beatelite commented 8 years ago

Thanks, I placed use AR6SAASPlans\Controllers\SignUpCtrl; in the routes.php and it's still throwing the error.

BTW, this wasn't mentioned in the documentation for the routes.

Tagging @giwrgos88 for some help since it looks like he's using routes effectively.

giwrgos88 commented 8 years ago

@beatelite did you tried not to include the twig and just do " dd("testing"); " in your controller?

giwrgos88 commented 8 years ago

also trycomposer dump-autoload

beatelite commented 8 years ago

@giwrgos88 thanks for chiming in. I did run composer dump-autoload and notta.

I also just tried in my controller:

<?php namespace AR6SAASPlans\Controllers;

class SignUpCtrl {

    /**
     * 
     *
    public function showSignUp()
    {
        return dd("testing");
    }
}

still getting the error.

My routes.php file:

<?php namespace AR6SAASPlans;

use AR6SAASPlans\Controllers\SignUpCtrl;

/** @var \Herbert\Framework\Router $router */

$router->get([
    'as'   => 'test',
    'uri'  => '/test',
    'uses' => __NAMESPACE__ . '\Controllers\SignUpCtrl@showSignUp'
]);
giwrgos88 commented 8 years ago

@beatelite can you make a zip file of your plugin so i can try it on a test server?

beatelite commented 8 years ago

Wow. That would be super helpful.Thank you!!

Here's the link: https://drive.google.com/file/d/0B-r5llGpXi8xQnpGc2ZieXB2VE0/view?usp=sharing

giwrgos88 commented 8 years ago

@beatelite on a fresh installation that I did, your routes are working fine. Try to disable all modules and leave only yours enable a try again.

jeremyzahner commented 8 years ago

@beatelite For me, it's the same as for @giwrgos88. Working well on a fresh installation.

baqeryan commented 7 years ago

I also have the same error. Do you fix this error?

beatelite commented 7 years ago

Nope. I ditched Herbert since it doesn't really look that active. i love the idea - a lot actually, but was worried about not enough community support.