NixNod Posted September 26, 2007 Share Posted September 26, 2007 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? Quote Link to comment https://forums.phpfreaks.com/topic/70813-application-design/ Share on other sites More sharing options...
448191 Posted September 27, 2007 Share Posted September 27, 2007 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. Quote Link to comment https://forums.phpfreaks.com/topic/70813-application-design/#findComment-356169 Share on other sites More sharing options...
NixNod Posted September 28, 2007 Author Share Posted September 28, 2007 Sup, verry good. I'v tested that, but if I want an dynamic thing like: members/view/123 (123) is the ID that I'll get on DB. What I'll do? Quote Link to comment https://forums.phpfreaks.com/topic/70813-application-design/#findComment-357394 Share on other sites More sharing options...
NixNod Posted September 28, 2007 Author Share Posted September 28, 2007 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 Quote Link to comment https://forums.phpfreaks.com/topic/70813-application-design/#findComment-357409 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.