deathbeam
-
Posts
22 -
Joined
-
Last visited
Posts posted by deathbeam
-
-
Most modern framework use autoloaders to including classes
Also see
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?
also, putting php settings into a .htaccess file only works when php is running as an apache module, which is uncommon on shared web hosting. so doing it the way you are trying would limit your framework to just apache servers and to just a fraction of those that have php running as a server module.
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.
-
Gosh, that design is messy. Try http://getbootstrap.com/getting-started
-
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.
-
Not sure what your talking about but php does have access modifiers
class phpfreak{ protected age; protected height; protected function getage(){ return $this->name; } protected function getheight(){ return $this->height; } } class create_freak extends phpfreak{ public function create_freak($age, $height){ $this->age = 20;//protected $this->height = 100;//Protected } public function get(){ return Array(parent::getage(), parent::getheight()); } } $create_a_freak = new create_freak();//calls constructor print_r($create_a_freak.get()); //gets values
Yes, it have protected, private and public. But it misses internal. Internal functions and vars are visible only in file.
-
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?
-
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?
-
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
-
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
-
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).
-
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
-
Welcome here. I personally do not like w3schools, but it have some valuable tutorials for beginners. Good luck with learning PHP
- 1
-
thanks for the feedback? I actually like the design, but that is not the reason for my post. When you have scrolled to the "About Me" section Resume is highlighted in the menu, and when you are in the "Resume" section Portfolio is highlighted in the menu.
I am using Chrome.
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.
-
Use full tags <?php and not short <? tags in your post title.
Ha, I thought that was amusing, welcome.
-
Yep, short tags aren´t enabled on some hosts so I was not sure if they are allowed on this site
-
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...
-
Notepad++ becouse my PC is too slow to handle PHPStorm
-
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.
- 1
-
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.
-
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.
-
No, no, you don't understand. Template inheritance means that I can create a base template and then override specific parts of it in subtemplates – similar to inheritance in OOP. This is incredibly useful and leads to very clean templates.
This can be done with closures.
Why is learning new tools such a big problem? A developer should be able to learn and use all kinds of tools, especially in web programming. If they can't, then, frankly, this job is not for them.
You're worried about performance? Do you have concrete figures at hand, or is this just a vague feeling? All modern engines cache the templates as plain PHP scripts, which means there's no technical difference between a handwritten PHP “template” and a Twig template after the initial parsing stage. I very much doubt that there's any significant performance loss. But feel free to prove your point.
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).
And that tells us what exactly? That you can throw together some lame tag replacer in 2 minutes? No doubt about that. But I'm talking about a professional template engine.
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....
How do you know what I need?
As I said, this is my subjective opinion, my 2 cents. It is feature without what I can continue living.
-
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
-
template engine !== new language.
You can learn in just two days how to use Twig or Blade.
That´s why I put language into " ". It is something like that, another thing to learn when you do not have to.
Until fairly recently I felt the same, however, you should read the points brought up by Jacques1 again. In particular, I can't go past: "PHP is a template engine from the 90s. It doesn't have any modern features whatsoever: no template inheritance, no auto-escaping, no custom tags."
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.
-
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.
I use Blade template engine. I like {{$var}} more than <?=$var?>
One example:
@if(true) asdsdasd @endif
is more readable than
<?php if(true): ?> asdasda <?php endif; ?>
It is similar enought. Why people should learn new "language" only for writing templates? HTML, CSS, JS and PHP is enought.
-
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>
Can this be simplified with regex?
in Regex Help
Posted
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.
And this is route method.