Coder Social home page Coder Social logo

Comments (5)

elnur avatar elnur commented on June 15, 2024

There is an example of routing using annotations right there in the answer. Have you checked it out?

from elnurabstractcontrollerbundle.

samlevin avatar samlevin commented on June 15, 2024

Yes, and thank you for your patience sir. I am just very confused about what is supposed to go inside "routing.yml" when you are defining controller as service AND using annotations for config. Any example?

from elnurabstractcontrollerbundle.

samlevin avatar samlevin commented on June 15, 2024

Man, Elnur, please. I'm still stuck friend.

The problem here, is I'm not sure what to put in Routing.yml when using Controller as a Service using your abstract parent class AND annotation routing.

I have the following Routing.yml file:
WebController:
resource: "HostingPick\Controller\WebController.php"
type: annotation

This is according to how you specify - with making Vendor/Controller in order to take controllers outside of bundle.

But I get this message:
Cannot import resource "HostingPick\Controller\WebController.php" from "/home/dir/trunk/HostCore/app/config/routing.yml". (The file "HostingPick\Controller\WebController.php" does not exist (in: /home/dir/trunk/HostCore/app/config, /home/dir/trunk/HostCore/app/Resources).)

Man, the thing is, this "resource" expects link to Controller file INSIDE a bundle:
resource: "@HostingPickWebBundle"

The above example works, when my WebController.php file is in HostingPick/Bundle/WebBundle directory. But this defeats the point of your example, for controllers to live outside of any bundle.

How to specify to 'resource' that my controller (which is defined as service), is outside of bundles??

Pls man, I'm not crazy. This is not common sense to me. How can your solution work with this constraint? what can I put in resources?

Here is other relevant config:

jms_di_extra:
locations:
all_bundles: false
bundles: [WebBundle]
directories: ["%kernel.root_dir%/../src"]

services:
WebController:
class: HostingPick\Controller\WebController
parent: elnur.controller.abstract

from elnurabstractcontrollerbundle.

elnur avatar elnur commented on June 15, 2024

Here's how I do it in routing.yml:

user:
    resource: Elnur\Controller\UserController
    type: annotation

As you can see, I have no .php at the end.

And here's how that controller starts:

<?php
namespace EP\Controller;

use Elnur\AbstractControllerBundle\AbstractController;
use JMS\DiExtraBundle\Annotation\Service;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;

/**
 * @Service("user_controller", parent="elnur.controller.abstract")
 * @Route(service="user_controller")
 */
class UserController extends AbstractController

Setting the service option on the controller wide @Route is important. I'm sure you can convert this to YAML if you prefer that format.

from elnurabstractcontrollerbundle.

samlevin avatar samlevin commented on June 15, 2024

Thank you :) 🎱

from elnurabstractcontrollerbundle.

Related Issues (8)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.