Jump to content

gizmola

Administrators
  • Content count

    4,717
  • Joined

  • Last visited

  • Days Won

    36

gizmola last won the day on June 21

gizmola had the most liked content!

Community Reputation

141 Excellent

About gizmola

  • Rank
    Prolific Member

Contact Methods

  • AIM
    gizmoitus
  • Website URL
    http://www.gizmola.com/

Profile Information

  • Gender
    Male
  • Location
    Los Angeles, CA USA

Recent Profile Visitors

The recent visitors block is disabled and is not being shown to other users.

  1. A symlink does not magically give you rights to anything that you don't have rights to on the non-symlinked folder, both from an ownership and permissions standpoint. It would also help if you specified what web server/php configuration you are running. There are settings like FollowSymlinks you might need to investigate and verify.
  2. gizmola

    Injecting arguments in constructors

    I'm glad you got the main point of my comments, being, don't try and hide dependencies inside an array you pass to the constructor. Your examples look similar to the type of code often associate with micro frameworks like Lumen, slim or silex. Looks fairly kosher to me given the limited context.
  3. gizmola

    Question regarding templates

    I would say that the standard for this would be creation of a style guide, which is a typical first step for a professional website designer. Things like a logo need to be seperate deliverables to be included into the style guide. Once the style guide exists, both the site template and letterhead can be derived and should look to be parts of the same thing. Take a look at this article: https://designmodo.com/create-style-guides/
  4. gizmola

    Injecting arguments in constructors

    I think you have to be careful with the terminology you are employing. An argument is by definition "injecting" variables into a function or method. In general the important distinction is how an argument is passed. Passed by Value: Changes to the argument don't change the original variable Passed by Reference: Changes to the argument change the original variable A fundamental change in PHP from version 4 to 5 was that all objects get passed by reference. In PHP 4 you frequently had to employ the 'reference' operator. So when the word "injection" gets used, it's in reference to "Dependency Injection". Obviously that is large topic, but it's predicated on the idea that you will inject objects that a class might depend on via the constructor. Since code in the class will reference this dependency, it should be a parameter and not passed in via an array. Now in terms of your specific example having to do with form data, it is hard for me to see the value of what you are doing when form data exists within PHP in a super global ($_POST). If you look at most of the frameworks, all of which have some support or solution for form building, validation and error handling, doing what you are doing is an anti-pattern. What you see more of is the use of a Request object that gets the raw form data from the request, then applies validations and updating of model objects as required. Just mapping an array of variables into an object seems of limited value.
  5. gizmola

    Hide address bar directory in hosting.

    You misunderstood my question. What webserver are you using? Rewrites are typically supported by the webserver itself, so it's important to know if you are using PHP with Apache (typically with mod_php) or using PHP with Nginx (typically using php-fpm).
  6. gizmola

    Hide address bar directory in hosting.

    What you are asking for does not make sense nor is it possible. What you could have is something like this: http://www.school.com/index/welcome Are you running Apache or Nginx?
  7. gizmola

    Do you see my coding error?

    Hopefully you already recognize that there is no mysterious math going on with your id's. The answer most likely is that you have 2 rows with first name of 'steve'. As suggested, you will gain insight by just doing a var_dump($row) inside your fetch loop until you are clear on what is happening. As suggested, please use bind variables for your query rather than interpolating your string. Example: $link = mysqli_connect(...); $stmt = mysqli_prepare($link, 'SELECT id, * FROM w WHERE first_name=?'); mysqli_stmt_bind_param($stmt, 's', $first_name); mysqli_stmt_execute($stmt); $result = mysqli_stmt_get_result($stmt); while ($row = mysqli_fetch_array($result, MYSQLI_ASSOC)) { var_dump($row); } Trying this input should show you the dangers of string interpolation and the way they lead to sql injection exploits:
  8. gizmola

    New Guru: maxxd

    Glad to have you on staff.
  9. gizmola

    Automatic Menu Generation

    I have to agree strongly with requinix here. There are many ways to format files to include configuration data that have support libraries and functions allowing you to read & write and convert them into data structures the language understands. The ones I typically see are .ini, yaml and xml. You also have the option of using a plain old php array and serialize(). Since your desire is to then manipulate this data and output html via javascript code, as suggested, json is the single best practice which you see used just about everywhere for REST api's as it is the best way to get serialized data into javascript objects. You could base your structure on a php array and use json_encode to convert it to json for output to your menu code, or just store it in json format on disk. Either way you will be able to accomplish what you want in a standard way that is highly supported both by php and javascript. Here's some code to consider: <?php $menu = array ('Menu1' => array('sub item1' => 'subitem1.html', 'sub item2' => 'subitem2.html'), 'Menu2' => array('sub item3' => 'subitem3.html'), 'Menu3' => array() ); var_dump($menu); echo json_encode($menu); Outputs: array(3) { ["Menu1"]=> array(2) { ["sub item1"]=> string(13) "subitem1.html" ["sub item2"]=> string(13) "subitem2.html" } ["Menu2"]=> array(1) { ["sub item3"]=> string(13) "subitem3.html" } ["Menu3"]=> array(0) { } } {"Menu1":{"sub item1":"subitem1.html","sub item2":"subitem2.html"},"Menu2":{"sub item3":"subitem3.html"},"Menu3":[]}
  10. gizmola

    Hide address bar directory in hosting.

    It is hard to understand what you mean. Can you clarify your question? Are you talking about using an IDE to access your site source files? If so, which one? Are you using an FTP client? Often clients and IDE that support remote access to files have ways to configure the home directory for a site. I interpreted your question to be along those lines.
  11. gizmola

    Firebase create Topic

    PHP has a nice function for you: json_decode(). Read the manual page for it! There is an option to either convert it to object format or an array. Use which ever form suits you.
  12. gizmola

    Firebase create Topic

    The last line of the script should output the result if you want to see anything. var_dump($result);
  13. gizmola

    Can an ORM do this?

    Most of the 'ORMs' across the popular web development languages are 'ActiveRecord' clones. On the surface of things, ActiveRecord is attractive to people for its simplicity. It offers a 1-1 mapping between a database table and a class. As the underlying design pattern for Laravel's eloquent and the ORM for most of the popular frameworks of the old school PHP days (Cake, Yii, Lithium, etc.), ActiveRecord leads to simple code like: $artist->setName('Robert Plant'); $artist->save(); Doctrine on the other hand is a 'Data-mapper' implementation, which is different design pattern. The first thing you notice is that you don't have the wonky $class-save() method. Instead you have an entity manager that keeps track of objects and saves things for you as needed when that is important. In cases where you might be adding a number of different objects within a transaction, the entity manager fits the underlying RDBMS transaction system. With ActiveRecord, you are never far from the underlying structure of a table. Doctrine2 on the other hand, is really trying to insulate you from the individual tables. For example, you can define the relationships between classes and after you've done that, you can interact with the related classes naturally, rather than having to manage each individual table or do joins. It separates searching and querying from the model/relational mapping into repositories, which keeps the actual object classes a lot leaner. You can have custom repository classes if you want them, but basic searching on one or more attributes comes as a built in. Doctrine has event handlers that let you create the equivalent of trigger code that executes when an entity is inserted or updated. At the point that you're creating something sophisticated, it provides you a features that go beyond what ActiveRecord can.
  14. gizmola

    Should properties with methods be public or private?

    You create a class, and the class has a public data structure in it that happens to be a simple one dimensional numerically indexed array. Things are working ok, so you start utilizing the class definition, and in your code you access the array using $foo->var.. Let's assume this is a large project and you are accessing that array all over the place. Now you realize that the structure of the array isn't ideal for what you are doing, so you change the internal class variable to be an array of objects. How much of your system did you break? Answer: everywhere you refer to $foo->var! If however, you only utilize public methods, then it is possible to change the internal data structure without breaking the entire system. So long as the original method continues to return the one dimensional array, it doesn't matter that you changed the internal data structure. In OOP this concept is referred to as "data hiding" and "encapsulation". The other option you left out of your question, is 'protected'. In general, your data should either by private or protected in order to hide it from the outside world. If you expect your class to be the parent/superclass for other classes that will inherit/subclass it, then you should choose protected if you will be accessing those properties in the subclass. If not, then make them private. Either way, you don't want to have public properties which can subvert your public API and violate Encapsulation.
  15. gizmola

    Set post value of checkbox to empty

    Purely speaking to your database design, in general, avoid NULL. A null value is essentially a state of value unto itself. In your case it sounds like you want to have a tinyint with default 0. That way if you do an insert without specifying a value, 0 will be inserted, which is generally compatible with 'false' in PHP. This is not a PHP issue but rather an HTML forms issue. If you have an 'unchecked' checkbox on a form, the checkbox will not exist in the $_POST. So in situations where you show a form and the box is unchecked, you won't find that form element at all. You have options as to how you want to handle that: Use some client-side javascript to set the checkbox value to something on the submit Check serverside and if you don't find the checkbox name in the $_POST, then interpret that as "unchecked" and add logic to your INSERT/UPDATE accordingly.
×

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.