Jump to content

Destramic

Members
  • Posts

    967
  • Joined

  • Last visited

Everything posted by Destramic

  1. this is what i wanted call_user_func_array(array(new $name(), "__construct"), $arguments);
  2. im using my own framework im building...now ive decided to go down the root of using helpersin my view class public function __call($helper, $arguments) { if (!$this->get_helper($helper)) { $instance = new $helper($arguments); $this->set_helper($helper, $instance); return $instance; } } now the __call works as i want it...but the problem is the $arguments var is an array and gets sent to the helper like that...what is the best way to tackle this...i'd like it to be send as a string as it is not a array (i think the __call method automatically makes the incoming string an array) if you could give me your help/suggestions please guys
  3. ok but calling $this->_title inside the template isnt exactly right is it?
  4. @nightsylr i decided to do it like you said... public function league($game_name, $league_name) { $rows = $this->leagues->fetch_league($game_name, $league_name); $this->view->head_title('test - hello'); $this->view->rows = $rows; $this->view->render('headers/header.html'); $this->view->render('leagues/league.html'); $this->view->render('footers/footer.html'); } if that is how you meant...now when the title is set it will assign the value to $this->_title ... but i dont want the title called like that in my header file...is there a way i can do this without changing the property name?
  5. ok i see now thank you...so what would be the best way to do this and include the header and footer to each controller?
  6. the problem im getting is with this line in the bootstrap $this->view->head_title('test'); the view property is only initiated in the league_controller and $this->view doesnt exsist within the bootstap but i call the bootstrap header in the league controller and it wont let me execute the head title...if anyone can help me on why or how i can over come this please....thank you (code below) bootstrap public static function header() { $this->view->head_title('test'); } leaugue_controller method public function league($game_name, $league_name) { Bootstrap::header(); $rows = $this->leagues->fetch_league($game_name, $league_name); $this->view->head_title()->set_separator()->prepend('hello'); $this->view->rows = $rows; Bootstrap::footer(); }
  7. my bad...but can you tell me if it is good or bad practice to use them the way i said?
  8. hey guys i used defined variables inside my index.php and these defined varaibles are called and used through the site...is this good or bad? defined varaibles define('DS', DIRECTORY_SEPARATOR); define('PARENT_DIRECTORY_PATH', dirname(dirname(__FILE__)) . DS); define('PUBLIC_DIRECTORY', BASE_URL . DS .'public' . DS); define('PRIVATE_DIRECTORY', BASE_URL .'private' . DS ); thank you
  9. would this be the correct way of doing it?...because i may way to add several scripts to that one javascript file...and that file will call the function and execute them there.
  10. ok thank you so instead i would need to do $registry = new Registry()->get_instance(); this is the first time ive really used instances and singletons in a class
  11. hey guys im wondering who to import a js file insdie another js file...for instance if i wanted to load function function from the library into a js file to execute them...if someone has any good ways/ideas/tips please
  12. also i tried echo $registry->config->db_username; inside my index and it works fine....something wrong with the static instance?...i cant work it out
  13. i think there is something wrong with the registry class index - where tyhe registy is made $config_root = 'config' . DS . 'config.ini'; $document = new Document; $config = $document->read($config_root); $registry = new Registry(); $registry->config = $config; model - where i want the data returned public function __construct() { $config = Registry::get_instance()->config; echo $config->db_username; }
  14. here you go...i hope someone can help...i know it is a small problem somewhere but i cant see where...to me the docuemt class works fine....but thanks @nightsylr document class <?php class Document { protected $_values = array(); function read($file_name) { $file_root = PRIVATE_DIRECTORY . $file_name; try { $file = fopen($file_root, 'r'); if (!file) { throw new Document_Exception(sprintf("Document '%s' was unable to be read.<br />\n", $file)); } else if (!file_exists($file_root)) { throw new Document_Exception(sprintf("Document '%s' doesn't exsist.<br />\n", $file)); } while ($i = fgets($file)) { if (!preg_match('/^\s*$/', $i)) { if (preg_match('/([A-Za-z0-9_]+) += +([A-Za-z0-9_.]+)/', $i, $found)) { $key = $found[1]; $value = $found[2]; $this->_values[$key] = $value; } else if (preg_match('/([A-Za-z0-9_]+)\[\] += +([A-Za-z0-9_.]+)/', $i, $found)) { $key = $found[1]; $value = $found[2]; if (!array_key_exists($key, $this->_values)) { $this->_values[$key] = array($value); } else { array_push($this->_values[$key], $value); } } } } fclose($file); return $this; } catch (Document_Exception $e) { echo $e->getMessage(); } } public function __get($key) { if (array_key_exists($key, $this->_values)) { return $this->_values[$key]; } } } ?>
  15. its not returning any value at all...that is the problem. line 10 where the error is $config = Registry::get_instance()->config;
  16. yeah i think the problem is getting the instance...ive tried what you said and it doest work at all sorry
  17. hey guys im having an error whilst trying to return an object registered in my registry class. the object in trying to get is a config document reader which should return things such as database details and setting of the website. if someone could help me please that would be excellent...i hope you understand Index - where the resigtry is made $config_root = 'config' . DS . 'config.ini'; $document = new Document; $config = $document->read($config_root); $registry = new Registry(); $registry->config = $config; Model - where the config is called but returns an error $config = Registry::get_instance()->config; echo $config->db_username; Registry class <?php class Registry { static protected $_instance = null; protected $_objects = array(); static public function get_instance() { if (self::$_instance == null) { self::$_instance = new self(); } return self::$_instance; } public function __set($key, $object) { $this->_objects[$key] = $object; } public function __get($key) { if (isset($this->_objects[$key])) { return $this->_objects[$key]; } return NULL; } } ?> return of the instant $this->_objects within the Registry class Array ( [config] => Document Object ( [_values:protected] => Array ( [developement_enviroment] => true [db_type] => mysql [db_host] => localhost [db_username] => root [db_password] => password [db_database_name] => test [default_controller] => news [default_action] => articles [autoloader_ignore_directories] => Array ( [0] => .buildpath [1] => .project [2] => .settings [3] => . [4] => .. [5] => tmp [6] => views [7] => public [8] => scripts [9] => .htaccess ) ) ) } )
  18. thank you..it works great i also took the left join of league matches out as it wasnt really need at all for the data i needed to be returned SET @rank := 0; SET @points := 0; SET @drawing := 0; SELECT *, @rank := IF(@points = points, IF(@points = '0', @rank + 1, @rank), @rank + 1), @points := points, @drawing := IF(@points = points, IF(@points = '0', @drawing = '0', @drawing = '1'), @drawing = '0'), IF(@drawing = '1', @rank + 1, @rank) as rank, @drawing := '0' FROM( SELECT t.team_id, t.team_name, COUNT(r.league_match_result_id) AS 'matches_played', SUM(IF(r.result='Win', 1, 0)) AS `wins`, SUM(IF(r.result='Loss', 1, 0)) AS `losses`, SUM(IF(r.result='Draw', 1, 0)) AS `draws`, SUM(IF(r.result='Win', 3, IF(r.result='Draw', 1, IF(r.result='Loss', 0, 0)))) AS `points` FROM teams t LEFT JOIN league_match_results r ON r.team_id = t.team_id LEFT JOIN team_leagues tl ON tl.team_id = t.team_id LEFT JOIN leagues l ON l.league_name = 'Counter-Strike Europeon Team Death Match' LEFT JOIN games g ON g.game_abbreviation = 'CSS' GROUP BY t.team_id ORDER BY points DESC, t.team_name) AS x just one more thing is the way i've designed the tables and is the query a good way of doing this? thank you again
  19. Destramic

    tables

    oh that simple...I just thought tables were bad
  20. that sounds like a session problem to me...an auth class is idealy what you want to save time and consistantcy
  21. Destramic

    tables

    hey guys i have rows for a database...now these row will create data for a league table (like the football league for example)...now how would be the best way to deal with the view of it...a table or should/could i use css?...thanks guys
  22. hey guys im creating a league and below you can see the tables and the query its self that im using. now the query resturns the results i need but the one thing it doesnt return is any teams that are in the league that dont have any match results...im not sure if the way i have designed this whole thing is correct...but im after pointers and i want to know how i can return the other teams to show up in the league that dont have any points or any data within the league_match and league_match_results. thank you tables - leagues league_id game_id league_name win_points loss_points draw_points games game_id game_platform_id game_name game_abbreviation teams team_id team_name league_matches league_match_id league_id challenger_id opponent_id league_match_results league_match_result_id league_match_id team_id result working query with 1 fault. SET @rank := 0; SET @points := 0; SET @drawing := 0; SELECT *, @rank := IF(@points = points, IF(@points = '0', @rank + 1, @rank), @rank + 1), @points := points, @drawing := IF(@points = points, IF(@points = '0', @drawing = '0', @drawing = '1'), @drawing = '0'), IF(@drawing = '1', @rank + 1, @rank) as rank, @drawing := '0' FROM( SELECT t.team_id, t.team_name, l.league_name, COUNT(r.league_match_result_id) AS 'matches_played', SUM(IF(r.result='Win', 1, 0)) AS `wins`, SUM(IF(r.result='Loss', 1, 0)) AS `losses`, SUM(IF(r.result='Draw', 1, 0)) AS `draws`, SUM(IF(r.result='Win', 3, IF(r.result='Draw', 1, IF(r.result='Loss', 0, 0)))) AS `points` FROM teams t LEFT JOIN league_match_results r ON r.team_id = t.team_id LEFT JOIN team_leagues tl ON tl.team_id = t.team_id LEFT JOIN league_matches m ON r.league_match_id = m.league_match_id LEFT JOIN leagues l ON l.league_id = m.league_id LEFT JOIN games g ON g.game_id = l.game_id WHERE l.league_name = 'Counter-Strike Europeon Team Death Match' AND g.game_abbreviation = 'CSS' GROUP BY t.team_id ORDER BY points DESC, t.team_name) AS x
  23. is see...its just my query is too complex to break down for my mysql db class. public function fetch_league($game_name, $league_name) { $variables = array('rank' => '0', 'points' => '0', 'drawing' => '0'); $query = "SELECT *, @rank := IF(@points = points, IF(@points = '0', @rank + 1, @rank), @rank + 1), @points := points, @drawing := IF(@points = points, IF(@points = '0', @drawing = '0', @drawing = '1'), @drawing = '0'), IF(@drawing = '1', @rank + 1, @rank) as rank, @drawing := '0' FROM( SELECT t.team_id, t.team_name, COUNT(r.league_match_result_id) AS 'matches_played', SUM(IF(r.result='Win', 1, 0)) AS `wins`, SUM(IF(r.result='Loss', 1, 0)) AS `losses`, SUM(IF(r.result='Draw', 1, 0)) AS `draws`, SUM(IF(r.result='Win', 3, IF(r.result='Draw', 1, IF(r.result='Loss', 0, 0)))) AS `points` FROM teams t LEFT JOIN league_match_results r ON r.team_id = t.team_id LEFT JOIN team_leagues tl ON tl.team_id = t.team_id WHERE tl.league_id = :1 GROUP BY t.team_id ORDER BY points DESC, t.team_name) AS x"; $league = $db->set($variables)->fetch_all($query, '1'); $rows = $league->get_rows(); return $rows; } thats were i was thinking of having a where() function that could inject into the query
  24. in fact ive been having a little reading about it and im no expert yet but something like this i need if you can help....bare in mind it obviously dont work $query = 'SELECT name, dob FROM users ORDER BY dob DESC '; $replace = "WHERE name = 'destramic'"; $test = preg_replace('(FROM)\s[a-zA-Z0-9](.*)(ORDER\S+BY)', $replace, $query); generate this: SELECT name, dob FROM users WHERE name = 'destramic' ORDER BY dob DESC
  25. but the thing is the name of the table could be anything. so... SELECT name, dob FROM users ORDER BY dob DESC needs to have WHERE name = 'destramic' added into the string to complete the sql query SELECT name, dob FROM users WHERE name = 'destramic' ORDER BY dob DESC i hope you understand
×
×
  • 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.