Jump to content

Application Design


NixNod

Recommended Posts

Hello, guys.

 

I got an question, I'm building an application skelecton that I'll use

for all others applications I'll develop, "Like an Framework".

I got some ideas, but I don't know which design implements.

 

Background:

The system will run arround the main class called "Core"

This class will have an Method for loading other classes (Singleton), this main class

core is used to log errors and others thigs, for example:

I got the DB class, when an error occours, it will log on Core.

So all child classes is loaded via "Core" and I got this Design:

 

<?php
$Core = new Core;
$Core->GetInstance('Scaffold'); //Loads the class and create the var object inside the core class
$Core->Scaffold->SayHello(); //Method inside Scaffold class.
?>

 

But to use the "Core" inside Scaffold (To call Log & Error functions) I

must declare Core as Global.

 

I Want something like that to application be a little more centred, and

not have a loads of objects.

 

Question(s):

1 This is an good design?

2 Other design can help me more?

3 There is an other way to optimize it?

4 The "Core" classe would be Global, I know it is not

good, what's the better way?

Link to comment
Share on other sites

1 This is an good design?

2 Other design can help me more?

3 There is an other way to optimize it?

4 The "Core" classe would be Global, I know it is not

good, what's the better way?

 

1. No.

2. Yes.

3. Yes.

4. Where do I start...

 

But to use the "Core" inside Scaffold (To call Log & Error functions) I
must declare Core as Global.

 

This is not true.

 

public function scaffoldFactory(){
   $this->scaffold = new Scaffold($this);
}
public function __construct(Core $core){
   $this->core = $core;
}

 

On a sidenote, if you declare $Core in the global space, you don't need to explicity declare it global. I would NEVER do something like this though:

 

public function doSomething(){
   global $core;
   $core->doSomethingElse();
}

 

You're asking for trouble with something like that.

 

In any case, you need to rethink this.

 

I usually recommend this tutorial for people just getting interresseted in centralizing application flow, avoiding globals and/or MVC.

 

Link to comment
Share on other sites

Nevermind, I'v just created an Function inside Router that get the segment by the number

 

<?php
    public function GetSegment($Seg) {
        $Route = (empty($_GET['route'])) ? '' : $_GET['route'];
        $Route = trim($Route, '/\\');
        $Segments = explode('/', $Route);
        return $Segments[$Seg-1];
    }
?>

 

So inside the View function inside Controller_Member

I'v added It:

<?php
print $this->Registry['Router']->GetSegment(4);
?>

 

Thanks

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.