Jump to content

Destramic

Members
  • Posts

    967
  • Joined

  • Last visited

Everything posted by Destramic

  1. hey guys im wanting to search a string and return a 1 - many results string = "controller/action/:game/:parameter" now in this instance i want to extract game and parameter but the string could consist of anything but i only want the values that look like :this :test :game :whatever i hope someone can help please....thanks
  2. hey guys im trying to result an array key and value if it has one...the code and results are below if anyone can help with this simple problem...thanks alot <?php $columns = array('news_id' => 'id', 'news'); foreach ($columns as $column => $column_alias) { echo $column . ' ' . $column_alias; } ?> the result im getting is: news_id id 0 news but im just after the result of just result the column name and alias (if it has one) so im looking for the result news_id id news
  3. I did really want to clone the property as $view...i could just do $this->_view but as I said I really would like to clone it across it that could be done
  4. hey guys i havent done any cloneing before but what im trying to do is clone $this->_view property in my Action class and pass it to my News_Controller class so i can call the View class by a varaible and not a property....can anyone help me and give me some advise on how i should do this...i tried below but i cant get it to work...thanks alot news controller class <?php class News_Controller extends Action { public function articles() { $view->title = "hello"; } } ?> action class <?php class Action { protected $_request; protected $_response; public $_view; public function __construct(Request $request, Response $response) { $this->set_request($request)->set_view(); $view = $this->clone_view(); $view->title = "hello"; $this->_response = $response; } protected function set_request(Request $request) { $this->_request = $request; return $this; } protected function set_view() { $this->_view = new View; return $this; } protected function get_request() { return $this->_request; } public function clone_view() { $view = clone $this->_view; return $view; } public function dispatch($method, $parameters) { if ($this->get_request()->is_dispatched()) { if(method_exists($this, $method)) { call_user_func_array(array($this, $method), $parameters); } else { } } } } ?>
  5. sorry haha...i must of just read if quickly but thanks for that ive seen your examples of your routing system so its something to go of...also do you know much about the zend framework?...im just wondering what the modules are actually for?...thanks again thorp
  6. Yeah an example on how the routing system would be great if you could please...and with the modules part I saw it on the zend framework...thanks for your help
  7. hey guys im currently making a framework at the moment which is working fine but i want to be able to add modules and a routing system but firstof all i dont know if i understand it fully if anyone can help. MODULES basically adding a module you would be able to direct controller: news action: articles like so $modules->add_module('news', array('controller' => 'news', 'action' => 'articles' )); which would direct http://domain.co.uk/news to the news / articles controlller and action ... is that how it should work? ROUTING and the routing to work as such $route->add_route(':username', array('controller' => 'user', 'action' => 'info')); so that the url from user/info controller and action would be http://domain.co.uk/destramic if someone could please help to shine a bit of light on this so i can understand a bit better please or if anyone has a good site or read up on this...thank you
  8. well thanks guys you've been very helpful...and ive finnished my autoloader class if you want to have a look basically it has a function which will read all files in the directory ending with .class.php and store the path so it is ready to be called <?php class Autoloader { private $_class_paths = array(); private $_ignore_directories = array(); private $_declared_classes = array(); public function __construct($config) { $this->_ignore_directories = $config->autoloader_ignore_directories; $this->get_class_paths(); spl_autoload_register(array($this, 'load_class')); } private function load_class($file) { $file = strtolower($file); $path = $this->_class_paths[$file]; try { if (!class_exists($file, FALSE)) { if (file_exists($path)) { require_once $path; $this->_declared_classes[] = $file; } else { throw new Autoloader_Exception(sprintf("Class '%s' not found.<br />\n", $file)); } } } catch (Exception $e) { echo $e->getMessage(); } } private function get_class_paths($path = ROOT) { $dh = opendir($path); while (false !== ($file = readdir($dh))) { if (!in_array($file, $this->_ignore_directories)) { if (is_dir($path . DS . $file)) { $this->get_class_paths($path . DS . $file); } else { if (preg_match("/\.class\.php$/i", $file)) { $file = substr($file, 0, -10); $this->_class_paths[$file] = $path . DS . $file . '.class.php'; } } } } closedir($dh); } public function declared_classes() { echo "<pre>"; print_r($this->_declared_classes); echo "</pre>"; } } if you guys can tell me what you think...or if you have any thing you think i should change please...thank you again
  9. Nightslyr thanks of the example i think thats what i need... just to use instead of throw new Autoloader_Exception throw new Exception
  10. ok so scrap the idea and just leave the class as it is without extending a exception handler
  11. well thats where i was gonna have Autoloader_Exceptions extents Exception { }
  12. ok thanks for your help...but can you give me and example on where extending exceptions would be good within a class....a forms class, mysql class?
  13. i know that but it does handle exceptions...i just thought it was a good way of handleing exceptions through another class?
  14. hey guys i have a script ive made which loads classes automatically when called...the script works fine but when i extend the class Autoloader_Exception and it comes back with the error Fatal error: Class 'Autoloader_Exception' not found in C:\www\library\autoloader.class.php on line 3 i might be missing something here but i dont know why the autoloader doesnt load the extended class if someone can please help me how i can extend the class please thanks <?php class Autoloader extends Autoloader_Exception { protected static $_declared_classes = array(); public static function load_class($class_name) { $class_name = ucwords($class_name); $file = self::get_class_path($class_name); try { if (!class_exists($class_name, FALSE)) { if (file_exists($file)) { require_once $file; self::$_declared_classes[] = $class_name; } else { throw new Exception(sprintf("Class '%s' not found.<br />\n", $class_name)); } } } catch (Exception $e) { echo $e->getMessage(); } } protected static function get_class_path($class_name) { global $classes; if (array_key_exists($class_name, $classes)) { return ROOT . DS . $classes[$class_name]; } } public static function declared_classes() { echo "<pre>"; print_r(self::$_declared_classes); echo "</pre>"; } } spl_autoload_register(array('Autoloader', 'load_class')); ?>
  15. thank i had to remove ^ and $ from the expression to make it work if (preg_match('/\w += +\w/', $i)) also im trying to match any strings in the format of test[] = hello test[] = bye the expression below does work im just wondering if there is any faults with it as im new to this...thanks else if (preg_match('/^^[A-Za-z0-9_][]$ += +[A-Za-z0-9_]/', $i))
  16. im in need of some help on a bit of regex...im trying to learn but my effort isnt work so i need some help please the problem im having is this part of the scipt if (preg_match('/^[A-Za-z0-9_]\s=\s[A-Za-z0-9_]$/', $i)) i want to beable to check the value is in the format of: test_123=test123_123 (only letter number and underscores) if anyone would could help me or give me some points on my regex i'd be very greatful thanks while ($i = fgets($file)) { if (!preg_match('/^\s*$/', $i)) { if (preg_match('/^[A-Za-z0-9_]\s=\s[A-Za-z0-9_]$/', $i)) { preg_match('/^(.*?)=(.*?)$/', $i, $found); $name = trim($found[1]); $value = trim($found[2]); $this->_values[$name] = $value; } } }
  17. thanks for you help
  18. this is the output of the array....you can see the whitespaces [developement_enviroment ] => true [mysql_host ] => localhost [mysql_username ] => root [mysql_password ] => test [mysql_database_name ] => test [autoload_ignore_directorys[] ] => .htaccess
  19. thanks wildteen88 i got it working now with if (!preg_match('/^\s*$/', $i)) now the one other problem i have with the script is that this line preg_match('/^(.*?)=(.*?)$/', $i, $found); will read spaces so say for instance this line in the .cfg file is like host = localhost then it will read the white spaces if they can be removed?
  20. basically my test file looks like this and the break is being read by my loop if anyone can please help host = localhost username = destramic password = test database = test ; this space here is being read by my loop developement = true
  21. hey guys this script below will load a document file...txt, ini, ctf etc...but if the file has a new line from (whitespace) its not finding it...im using if (preg_match('\S', $i) == false) if that is the correct way to find a new line/white space within a txt document if someone could tell me what im doing wrong please function read($file_name) { $this->_file_name = $file_name; $file = fopen($this->_file_name, 'r'); while ($i = fgets($file)) { if (preg_match('\S', $i) == false) { preg_match('/^(.*?)=(.*?)$/', $i, $found); $this->_values[$found[1]] = $found[2]; } } fclose($file); print_r($this->_values); }
  22. hey guys i have a an array and i want to know if i can call the value without having to put the array key in capitals. here is my array Array ( [DEVELOPEMENT_ENVIORMENT] => 1 [MSQL_HOST] => localhost [MYSQL_USERNAME] => root [MYSQL_PASSWORD] => test [MYSQL_DABASE_NAME] => test ) can i call the array like $array['mysql_host']Array ( [DEVELOPEMENT_ENVIORMENT] => 1 [MSQL_HOST] => localhost [MYSQL_USERNAME] => root [MYSQL_PASSWORD] => n0real1ty [MYSQL_DABASE_NAME] => test ) can i call the array like $array['mysql_host'] instead of $array['MYSQL_HOST'] whichout renaming the array key if anyone could help please...thank you
×
×
  • 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.