L4URO Posted December 9, 2013 Report Share Posted December 9, 2013 Čau, Tā tad,cik saprotu,tad $_instance mainīgais DB klasē ir DB instance,kad funkcija tiek izsaukta,kam pieejamas visas DB klases funkcijas.Kad tiek izsaukts self::$_instance = new DB(); tad aiziet __constructor metode un $_instance tiek pievienots _pdo, tad šis mainīgais tiek atgriezts. Es pareizi tik tālu sapratu? Un tad,kad kādā mainīgajā raksta $user = DB::getInstance(); , tad $user praktiski ir vienāds ar $_instance mainīgo? Un ja raksta $user = DB::getInstance()->query(); ,tad query funkcija pieder $user mainigajam vai $_instance metodei? $user = DB::getInstance(); <?php class DB { private static $_instance = null; private $_pdo, $_query, $_error=false, $_results, $_count=0; private function __construct () { try { $this-> _pdo = new PDO('mysql:host='.Config::get('mysql/host').';dbname='.Config::get('mysql/db'),Config::get('mysql/username'),Config::get('mysql/password')); }catch(PDOException $e){ die($e->getMessage()); } } //singleton,the instance can be created only once public static function getInstance(){ if (!isset(self::$_instance)) { self::$_instance = new DB(); } return self::$_instance; } } Paldies ,ja kaut ko nesaprotat, tad prasat! Quote Link to comment Share on other sites More sharing options...
marrtins Posted December 10, 2013 Report Share Posted December 10, 2013 (edited) Un ja raksta $user = DB::getInstance()->query(); ,tad query funkcija pieder $user mainigajam vai $_instance metodei? Abiem. T.i., abi mainīgie referencē uz vienu objektu. Edited December 10, 2013 by marrtins Quote Link to comment Share on other sites More sharing options...
L4URO Posted December 10, 2013 Author Report Share Posted December 10, 2013 Abiem. T.i., abi mainīgie referencē uz vienu objektu. ok,paldies,bet kaa ir ar sho? $user = DB::getInstance(); , tad $user praktiski ir vienāds ar $_instance mainīgo ? parejo es sapratu? Quote Link to comment Share on other sites More sharing options...
Kemito Posted December 10, 2013 Report Share Posted December 10, 2013 L4URO, nevis prakstiski, bet ir. Mainīgajam "user" Tu piešķirt attiecīgo vērtību, ko saturn mainīgais _instance. "ķipa $user = $_instance" Quote Link to comment Share on other sites More sharing options...
L4URO Posted December 10, 2013 Author Report Share Posted December 10, 2013 L4URO, nevis prakstiski, bet ir. Mainīgajam "user" Tu piešķirt attiecīgo vērtību, ko saturn mainīgais _instance. "ķipa $user = $_instance" ok,tam ari gribeju dzirdet apstiprinajumu :D Quote Link to comment Share on other sites More sharing options...
Brašais Posted December 12, 2013 Report Share Posted December 12, 2013 o! paldies par info, man nesen atpakaļ bija arī uzradies līdzīgs jautājums.. Quote Link to comment 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.