Jump to content

Destramic

Members
  • Posts

    960
  • Joined

  • Last visited

Everything posted by Destramic

  1. 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
  2. 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
  3. Nightslyr thanks of the example i think thats what i need... just to use instead of throw new Autoloader_Exception throw new Exception
  4. ok so scrap the idea and just leave the class as it is without extending a exception handler
  5. well thats where i was gonna have Autoloader_Exceptions extents Exception { }
  6. 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?
  7. i know that but it does handle exceptions...i just thought it was a good way of handleing exceptions through another class?
  8. 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')); ?>
  9. 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))
  10. 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; } } }
  11. thanks for you help
  12. 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
  13. 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?
  14. 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
  15. 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); }
  16. 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
  17. hey guys im having a problem with my class it sees the constructor isnt loading and this line isnt executed spl_autoload_register(array($this, 'load_class')); i dont see why not if anyone can help please <?php class Autoloader { private static $_declared_classes = array(); private static $_ignore_files = array(); public function __construct() { spl_autoload_register(array($this, 'load_class')); } 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(); } } private 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>"; } ?>
  18. ok but the file name could be the size of font_controller.class.php...that would work fine?
  19. hey guys im not that good when it comes to regex...im after the syntax were a string(filename) will have .class.php inside please if anyone can help. examples: test.class.php, help.class.php ...etc thank
  20. exactly what i wanted...thanks alot
  21. ok this is what i have at the moment. <?php if ($handle = opendir('../')) { while (false !== ($file = readdir($handle))) { echo $file . "<br />"; } closedir($handle); } ?> now in this loop it shows folders...but what i want to do is if the $file is a folder then open that up and read directory
  22. hey guys im tyring to read my directory (whole of the web server)...i want to be able to put the file name and root into an array...im just wanting to know whats the best function i need to do this 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.