Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8193323
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T04:26:33+00:00 2026-06-07T04:26:33+00:00

I’m trying this mini framework for the first time and this is my first

  • 0

I’m trying this mini framework for the first time and this is my first time at all using justa a framework:)
I added the doctrine service to my index.php file like this:

$app->register(new Silex\Provider\DoctrineServiceProvider(), array(
    'db.options' => array(
        'driver'   => 'pdo_sqlite',
        'path'     => __DIR__.'/../include/database.sqlite',
    ),
));

and I create a new file with a class with a static method that resturn an array, for example.

<?php

namespace MyNameSpace;


class myClass{

    static function getStuff(){


       return array(1 => array('foo'=> 'bar',
                               'bar' => 'foo',
                              )
                   );

    }

}

As you can see it’s hardcoded so I decide to use a database (sqlite is enought) but I don’t know how to get access to $app variable inside my file.

On the other way, all the tutorials that I can find online are confusing and referred to a old Silex’s version with the .phar file that now is deprecated, and the directory structures of all examples I found are differente from mine (taken from the fat Silex zip file)

The directory structure of my project is this:

├── composer.json
├── composer.lock
├── src
│   └── MyNameSpace
│       └── myClass.php
├── vendor
│   └── composer
│   └── doctrine
│   └── silex
│   └── ...
│   └── **autoload.php**
└── web
    └── css
    └── img
    └── js
    └── views
    └── .htaccess
    └── index.php
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-07T04:26:35+00:00Added an answer on June 7, 2026 at 4:26 am

    First thing you need to know is that accessing $app is a bad practice. You should DI when it is possible. If you really want to do that, check the code below.

    Inside index.php (usually bootstrap.php) declare a new service:

    $app['my_class'] = $app->share(function() use ($app) {
        // Retrieve the db instance and create an instance of myClass
        return new \MyNameSpace\myClass($app['db']);
    });
    

    Add a constructor sur myClass:

    namespace MyNameSpace;
    
    class myClass
    {
        /**
         * The connection
         *
         * @var \Doctrine\DBAL\Connection
         */
        private $db;
    
        /**
         * Constructor
         *
         * @param $db \Doctrine\DBAL\Connection
         */
        public function __construct($db)
        {
            $this->db = $db;
        }
    
        // ...
    }
    

    Then you can retrieve a fully initialized instance of myClass like this:

    $myClass = $app['my_class'];
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
this is what i have right now Drawing an RSS feed into the php,
I'm using v2.0 of ClassTextile.php, with the following call: $testimonial_text = $textile->TextileRestricted($_POST['testimonial']); ... and
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
We're building an app, our first using Rails 3, and we're having to build
I'm trying to create an if statement in PHP that prevents a single post
I'm making a simple page using Google Maps API 3. My first. One marker
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
I am trying to understand how to use SyndicationItem to display feed which is
Basically, what I'm trying to create is a page of div tags, each has

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.