Atli's Profile User Rating: *****

Reputation: 3926 Guru
Active Posts:
7,078 (3.54 per day)
08-June 10
Profile Views:
Last Active:
User is offline Today, 03:03 PM

Previous Fields

OS Preference:
Favorite Browser:
Favorite Processor:
Favorite Gaming Platform:
Your Car:
Dream Kudos:
Expert In:
PHP, Databases, Web Development
Icon   Atli has not set their status

Posts I've Made

  1. In Topic: Cannot redeclare class Magento

    Posted 22 Nov 2015

    You could use an IDE, or an editor like Notepad++, to replace all occurrences of those functions within the project/directory.

    Unless they are using them for templating, there shouldn't be any negative effect.
    It's definitely worth a try.

    Just make sure you create a backup of the files before hand, so you can roll back if there are problems.
  2. In Topic: Cannot redeclare class Magento

    Posted 22 Nov 2015

    Moved to the PHP forum. This is an issue specific to PHP, as opposed to web development in general.

    Usually when you see this kind of an error, it's because the same class file is being included multiple times.

    For example, you might include two classes that both rely on a third class, and both include that third class. That would cause an issue when you include those two classes, because the third class would be included twice.

    It's a good rule, when you are not using autoloading to manage includes for you, to use the include_once (or require_once) functions, as opposed to their simpler versions. ("include()" and "require()".) That'll ensure that the same file never gets included twice like that.

    My advice would be to go through your source code looking for places where the class(es) in the error are included, and replace the functions with their "_once()" counterparts.
  3. In Topic: MVC Forum Submission help

    Posted 19 Nov 2015

    I realize belatedly that the above post isn't altogether useful to your specific situation. More in a theoretical sense than a practical one, I suppose.

    It's not overly hard to make a simplified version of this, though, that can be used in smaller frameworks with less "under-the-hood" stuff going on than large frameworks like Symfony.

    Consider a (kind of) factory class like this:
    namespace MyCustomFramework\Core;
    class ModelFactory
        /* *************************************************
         * Singleton Methods - To simplify access to the
         * factory, since there is no bootstrapping to be
         * counted on.
         * *************************************************/
        /** @var ModelFactory */
        private static $factory;
         * @param \PDO $pdo
         * @param string $baseNamespace
        public static function initialize(\PDO $pdo, $baseNamespace="\\")
            if (!(self::$factory instanceof ModelFactory)) {
                self::$factory = new ModelFactory($pdo, $baseNamespace);
         * Get an instance of the request model.
         * Model path should look like: "FooBundle:BarModel"
         * @param string $modelPath
         * @return object
        public static function getModel($modelPath)
            return self::$factory->_getModel($modelPath);
        /* *************************************************
         * Instance Methods
         * *************************************************/
        private $db;
        private $baseNamespace;
        private $instanceRegistry;
        private function __construct(\PDO $pdo, $baseNamespace)
            $this->db = $pdo;
            $this->baseNamespace = $baseNamespace;
            $this->instanceRegistry = [];
        private function _getModel($modelPath)
            if (!isset($this->instanceRegistry[$modelPath])) {
                $ns = $this->_parsePath($modelPath);
                $this->instanceRegistry[$modelPath] = new $ns($this->db);
            return $this->instanceRegistry[$modelPath];
        private function _parsePath($path)
            list($bundle, $modelName) = explode(":", $path);
            $ns = $this->baseNamespace . "\\" . $bundle . "\\Model\\" . $modelName;
            if (class_exists($ns)) {
                return $ns;
            } else {
                throw new \RuntimeException("Invalid module path.");

    It assumes a namespace structure for the framework that is identical to that of Symfony, though that is easily changed.

    So assuming you had model classes located in places like:
    - DIC\BlogApp\AdminBundle\Model\UserModel
    - DIC\BlogApp\BlogBundle\Model\PostModel

    You could use this factory class in your framework in two simple steps:

    • First, initialize it somewhere near the main entry point of your application. Perhaps in the main script, or a router, or even a base controller constructor. Something like that.
      $db = new \PDO("mysql:etc...");
      ModelFactory::initialize($db, "DIC\\BlogApp");

    • And then you can use the model factory anywhere, like in your controllers:
      $model = ModelFactory::getModel("BlogBundle:PostModel");
      $posts = $model->loadPage($pageNumber);

    Just like with the Symfony code in the previous post, the controller is now completely separated from the data layer, and each model class is isolated, easily reusable and testable.
  4. In Topic: MVC Forum Submission help

    Posted 19 Nov 2015

    You'll always have to pass the database object into the model somehow. There is no way of getting around that, even if you go the route of using a Singleton, or something of that kind. (Which I don't really recommend.)

    Larger frameworks take care of that kind of bother for you, by managing all of this behind the scenes. If I keep using Symfony as an example, a model class like that would typically be defined as a service, making it accessible through the container in the controller.
    /** @var FooBundle\Model\StatusModel $model */
    $model = $this->container->get("foo.model.status");
    $status = $model->getDefaultStatus();

    The model class itself would be defined to take in the database object (EntityManager, generally, in the case of Symfony) either through the constructor or through an accessor method.
    namespace FooBundle\Model;
    use Doctrine\ORM\EntityManager;
    class StatusModel
        /** @var  EntityManager */
        private $em;
        public function __construct(EntityManager $em)
            $this->em = $em;
         * Finds some sort of default status.
        public function getDefaultStatus()
            return $this->em->getRepository("FooBundle:Status")->findOneBy([
                "isDefault" => true

    The model would be linked up with the container through configuration files, where you would specify what database object (EntityManager, or whatever you are using) should be provided for the constructor.
    # FooBundle/Resources/config/services.yml
            class: FooBundle\Model\StatusModel
            arguments: ["@doctrine.orm.entity_manager"]

    This keeps the controllers very clearly separated from the database layer. The controller actions themselves are never even aware of which database connection is being used to spawn the models, they just call them from the container and leave it up to the configuration.
  5. In Topic: MVC Forum Submission help

    Posted 16 Nov 2015

    In my opinion you are doing a little bit too much DB interaction in the controller. That sort of thing should belong to the Model layer, really. - You've got a CRUD DB interface in there, it seems, but still you are essentially creating whole SQL statements in the controller code, complete with conditions and sort orders:
    $ps = $this->db->select('statuses', 'id', array(), 'default_status=1', 'id ASC LIMIT 1');

    Ideally you'd be doing something akin to:
    $dbm = new StatusModel();
    $ps = $dbm->getDefaultStatus();

    And then the model code would deal with all the details of that DB interaction.

    This way it can be very easily re-used and tested. This is obviously a rather trivial example, but in general this makes a huge difference in large systems.

    As for the request data, it's not overly difficult to create (or even just re-use) an OOP interface for it. For example, I rather like how Symfony does it, using dependency-injection in the action method signature to pass a Request object, complete with all the passed data:
    namespace FooBundle\Controller;
    use Symfony\Bundle\FrameworkBundle\Controller\Controller;
    use Symfony\Component\HttpFoundation\Request;
    use Symfony\Component\HttpKernel\Exception\BadRequestHttpException;
    class BarController extends Controller
        public function indexAction(Request $request)
            $post = $request->request;
            if ($post->has("message")) {
                $twitterApi = $this->container->get("twitter.api");
                $success = $twitterApi->tweet($post->get("message"));
                return $this->render("resultview.html.twig", ["success" => $success]);
            } else {
                throw new BadRequestHttpException("Username is required.");

    Also note how it uses the $this->container object to access services outside the controller. It's not immediately creating references to all of them in the controller constructor, like you do with your $reqistry object, but rather making them accessible through it, creating them on-demand.

    Obviously Symfony's bootstrapper is a little more advanced than most people would try to build themselves, but it's not altogether difficult to replicate these concepts in a simpler form, fitting your own framework.

My Information

Member Title:
Enhance Your Calm
29 years old
September 5, 1986
Full Name:
Atli Ţór Jónsson
Years Programming:
Programming Languages:
Expert: PHP, SQL (MySQL, MSSQL), Web Development (HTML, CSS, Javascript, jQuery).

Studying: AngularJS, Node.js, Python, Ruby.

Dabble in: C#, VB.NET, Java, ActionScript 3, LUA, C/C++

Contact Information



  • (2 Pages)
  • +
  • 1
  • 2
  1. Photo

    khaichua Icon

    24 Nov 2015 - 16:42
    You can give yourself a look at Huffman file Code.h and HuffmanCode.cpp.
    Thank you very much
  2. Photo

    Anuraj23 Icon

    24 Nov 2012 - 00:43
  3. Photo

    Atli Icon

    21 Sep 2012 - 03:19
    Hey lyster. Please post questions like that in the forums. That's what they're there for.
  4. Photo

    lyster Icon

    21 Sep 2012 - 00:40
    i just can't figure out what are the possible tables,,i want to know normalization well..u_u
  5. Photo

    lyster Icon

    21 Sep 2012 - 00:34
    hi there mr. atli..i hope you could give me some advices and idea on how to make an erd on my mini mortuary_system,thanks god bless you..
    by the way im a student of a state college here in the philippines.
  6. Photo

    kimimimi Icon

    26 Aug 2012 - 00:37
    please help me
  7. Photo

    xenoslash Icon

    19 Jul 2012 - 23:35
    You are quite possibly the most helpful member of the community. I wish I could +1 you more than once for every long (and useful!) post you make.
  8. Photo

    Maryam.m Icon

    23 Jun 2012 - 10:52
    hey i understood what should i do!!!
    i'm so happy :D :D
  9. Photo

    polyosis Icon

    11 Jun 2012 - 16:49
    I would like to thank you on your advice with my site path and installation problems, you are most kind my friend.
  10. Photo

    Atli Icon

    14 Apr 2012 - 05:22
    Yea it seems to like you, Dimitri ;)
  11. Photo

    DimitriV Icon

    08 Apr 2012 - 19:20
    Your avatar… it blinked at me.
  12. Photo

    Atli Icon

    06 Nov 2011 - 19:49
    Hehe. Thanks guys :)
  13. Photo

    Dogstopper Icon

    06 Nov 2011 - 19:19
    Lookin' a little blue there. Cheer up man! You're a mod! Congratz!
  14. Photo

    codeprada Icon

    06 Nov 2011 - 18:34
    It's about time. Congrats on reaching blue status.
  15. Photo

    n00l3 Icon

    05 Sep 2011 - 12:59
    Happy birthday! :D
  • (2 Pages)
  • +
  • 1
  • 2