Jump to content

deathbeam

Members
  • Posts

    22
  • Joined

  • Last visited

Everything posted by deathbeam

  1. So, I am not very experienced with regexes, so I wanna ask if this code can be simplified with preg_match? It is code from my framework on what I am working for adding routes. To explain what is "default" and "MAP", here is example usage. And, callable is called via call_user_func_array if that helps. // mapping routes $fw->route('home: GET|POST /', 'home'); // provide ReST interface by mapping HTTP requests to class method $fw->route('MAP /rest', 'some_class'); // default route (404 page) $fw->route('default', 'error'); And this is route method. public function route($pattern, $callable) { $pattern = strtr($pattern,array(' '=>'')); if ($pattern == 'default') { $this->default_route = $callable; return $this; } $arr = explode('/', $pattern, 2); $method = $arr[0]; $route = '/'.$arr[1]; if (strpos($arr[0], ':') !== false) { $arr = explode(':', $arr[0], 2); $name = $arr[0]; $method = $arr[1]; } if ($method == 'MAP') { foreach ((explode('|', self::Methods)) as $method) { $this->route((isset($name)?$name.':':null).$method.$route, $callable.'->'.strtolower($method)); } return $this; } $this->routes[] = array($method, $route, $callable, isset($name)?$name:null); return $this; }
  2. I was not asking about using autoloader, that will defeat purpose of simplifying my code, why should I use autoloader when my framework is only single php file? Oh, thank you very much for this info. I am focusing on ability to use my fw on shared hosting, so then I will scrap this idea.
  3. Gosh, that design is messy. Try http://getbootstrap.com/getting-started
  4. There is also another scenario. Like this: class base{ public function setParam($key, $callable){ $this->params[$key] = $callable; } internal function run(){ foreach($this->params as $key=>$callable) $callable(); } } $base = new Base(); // if internal was possible, users will not be able to call this method outside this file. Especially usefull for frameworks and PHP applications. $base->run(); If you know what I mean. And yes, PHP isn´t C#, but PHP hosting is cheaper than ASP.NET. So it is pity that internal does not exists in PHP.
  5. Yes, it have protected, private and public. But it misses internal. Internal functions and vars are visible only in file.
  6. So I am working on my own PHP framework and I am using this: php_value auto_prepend_file library/fw.php php_value auto_append_file library/fw.php To auto prepend and append file. In that file I have check if instance of core class located in fw.php is defined so it will not prepend and append duplicates. With this I reduced index.php code by these 2 lines // This should be at beggining of index php $fw = Base::getInstance(); // This should be at very end of index.php $fw->run(); Is it good or bad way?
  7. Only thing I really miss from PHP is "internal" access modifier. Before I was making libraries and extensions in C# (like game frameworks, Tiled implementations, GUI loaders). Now, when I am working on my own PHP framework, I really miss internal, I was using it a lot in C#. Is internal planned to be added in PHP 7 or is it already in PHP 5.6 or it will never be added?
  8. If you are using windows, then simply download https://windows.github.com/ GitHub for windows so you do not have to learn git at all
  9. If you are echoing PHP values to html and you need to rewrite all relative links then yes, this is probably best method. Otherwise use simple string merging and echo values with var like $newURL. before them
  10. I am always using PDO bind when using prepary (actually, If you will not use bind and pass value directly to prepary it will throw exception).
  11. It will change to what url will point relative urls in your document. F.E when your domain is www.example.com, this relative path <a href="test">Test relative link</a> will point to www.example.com/test. But if you will change base to f.e this one <base href="http://www.new_example.com/"> "Test relative link" will point to www.new_example.com/test
  12. Welcome here. I personally do not like w3schools, but it have some valuable tutorials for beginners. Good luck with learning PHP
  13. I am using chrome too, and when I scroll to About Me, About Me is highlighted and same is with Resume. On my PC your site is working perfectly.
  14. Yep, short tags aren´t enabled on some hosts so I was not sure if they are allowed on this site
  15. So I was working on this site past month. I know it is too much time for such simple website, but I am a perfectionist and I need to have everything perfect. It is using JQuery, Twitter Bootstrap (I am deep fan of TWBS and I am using it on almost every website I make) and Yeti(?probably, I forgot ) theme from Bootswatch. Of course also FontAwesome for YT, FB, Twitter an GitHub icons. On smaller resolutions it is looking epic (1024x768 etc etc), on mobile devices too, but I am not sure how it looks on HD, HD-ready resolutions (yes, I can use zoom-out in my browser, but it is misleading...). What do you think? P.S.: Projects in "My Recent Work" are clickable and that will toggle description with some fancy fade effect (using jQuery.toggle()). P.S.2: I am not sure if I should vertically-center contact text or let it be with big top and bottom padding. What do you think? P.S.3: Oh, I almost forgot. Website link is here http://deathbeam.github.io/. Yes, I am using GitHub pages, I love git. And nope, I do not bought my own domain yet. P.S.4: I accept "brutal" criticizm, feel free to be rude P.S.5: (this is starting to be annoying lol): If you guys have time, can you please tell me what feeling do you have from my subsite http://deathbeam.github.io/fwphp/index.htm. I tried to keep everything as simple as possible, but I am not sure if it is not too much :/ P.S.6: I am really sorry for my English...
  16. Notepad++ becouse my PC is too slow to handle PHPStorm
  17. If you are not echoing your configuration from config.php and mail.php, then it is safe. When users will open config.php they will see blank page.
  18. I am using something like this for storing files if($_SERVER['REQUEST_METHOD'] == 'POST') { preg_match('/\.([a-zA-Z]+?)$/', $_FILES['userfile']['name'], $matches); if(in_array(strtolower($matches[1]), $accepted)) { $newname = md5_file($_FILES['userfile']['tmp_name']).'.'.$matches[1]; move_uploaded_file($_FILES['userfile']['tmp_name'], $filedir.'/'.$newname); } } Where '$accepted' is array of allowed file extensions and '$filedir' is subdirectory to store images. I am using 'md5_file' for unique names for images. Then you can simply pass '$newname' to database what is containing other data such as uploader and description like you stated in OP.
  19. For me it is working perfectly. But, to be honest, I must say that your site is not one of the best. That box shadow on that boxes with that big border radiuses are looking horrid Maybe it is not you but that theme, so consider changing it.
  20. This can be done with closures. It isn´t problem and I was using both Smarty and Twig. But I am not fan of them. Why? Becouse IMO it is overkill. I never liked using more code than I need, and using XXXKBs more of code just to have comfortable way to differ presentation from bussiness logic is not my style. PHP short tags and alternative tags like endif, endfor etc are enought readable for me. And yes, modern templating engines are caching their templates, but they still need to cache them at first load (and re-cache after every modification) and that takes some more miliseconds (yes, it isn´t noticeable, but it IS performance lost). Okay, I agree and this is valuable point for me (yes, it is still my own opinion, I know that others can have different opinions on this). Again, I will repeat what I said before. I do not like using more code than I need. And using professional template engine only becouse it have great auto-escaping feature.... As I said, this is my subjective opinion, my 2 cents. It is feature without what I can continue living.
  21. So I am just wondering to what music/genres you guys are listening too when working on something. This is somewhat forum game, so I will start. When I am programming something, I am mostly listening to metal (almost all genres of metal, including nu-metal and metalcore). Right now I am listening to Sabaton - Primo Victoria
  22. That´s why I put language into " ". It is something like that, another thing to learn when you do not have to. Template inheritance can be done with "include". Auto-escaping can be done with simple preg_replace when using object buffering to get PHP file. Here is stripped down example what I am doing: public function draw($file) { extract($this->fields); ob_start(); include $file; $html = ob_get_clean(); echo preg_replace("insert auto","escaping here", $html); } And custom tags? Not needed really. But I agree that Jacques is right in most of his points, but properly used PHP as template engine is a lot better than using 3rd party or custom-built template engines in terms of speed and without longer learning curve.
  23. IMO better is use PHP as templating language, becouse PHP IS templating language. Using template engines like Smarty, Twig, Blade or Moustache is imo only slowing your code. It is similar enought. Why people should learn new "language" only for writing templates? HTML, CSS, JS and PHP is enought.
  24. Here is basic HTML5 layout for you: <!-- PHP code here --> <!doctype html> <head> <meta charset="utf-8"> <title>The Default Template</title> <!-- CSS, favicons etc goes here --> </head> <body> <header> </header> <section> </section> <footer> </footer> <!-- Place your javascript here --> </body> </html>
×
×
  • 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.