Jump to content


  • Content Count

  • Joined

  • Last visited

Community Reputation

9 Neutral

About ckrudelux

  • Rank
    Invested Member
  • Birthday 10/25/1989

Previous Fields

  • Languages
    Swedish, English, HTML, CSS, XML, JS, PHP, SQL, PYTHON

Contact Methods

  • Website URL
  • ICQ

Profile Information

  • Location
  • Interests
    Problem solving, Driving and Being creative
  1. How would I unset a cookie with an unknown path? What I'm trying to do is to automate the task of removing the session if nothing is stored in the session variable. But I'm trying to implement so that I could use different sessions in different folders which makes the path more or less unknown. I know this might not be a good way of doing it but still I'm curious to know.
  2. ckrudelux

    OOP, PHP and MYSQL

    I been thinking for a long time about how to treat DB with PHP in a good way. I get stuck at if I should have a method creating the tables the class needs or I just create the table manually then I would need the class in a project. So I started to search a bit on the topic and got some articles about data mappers which uses a class to do the bidding between the program and the database. Article: http://www.slideshare.net/vlucas/building-data-mapper-php5-presentation Still I feel like I haven't found any good answers to my question on how the DB should be implement, maybe I just think about it too much. So I post this thread here in need of guidance, where my brain simply just make thing too complicated.
  3. Oh.. should have thought about that.. thank you very much
  4. This is the exact code but it should be the same as the example. private function updateChildren(Menu $menu){ if(count($menu->getItems())){ if($insert = DB::PDO()->prepare("INSERT INTO `menu` (`label`,`path`,`parent`) VALUES (:label, :path, '". intval($menu->getID()) ."')") && $update = DB::PDO()->prepare("UPDATE `menu` SET `label`=:label, `path`=:path WHERE id=:id")){ foreach($menu->getItems() as $item){ if($item->getID()){ if($update->execute(array("label"=>$item->getLabel(),"path"=>$item->getPath(),"id"=>$item->getID()))){ $this->updateChildren($item); } }else{ if($insert->execute(array("label"=>$item->getLabel(),"path"=>$item->getPath()))){ $item->__construct(intval(DB::PDO()->lastInsertID())); $this->updateChildren($item); } } } } } if(count($menu->getRemoved())){ foreach($menu->getRemoved() as $remove) $this->removeMenu($remove); } } I tested it by var_dump() the insert and update variables
  5. PHP is a server side language and can not interact with the html.You can look at it like php is writing you a html file and then sends it to the browser. What you do is you create an other php file which disblays the description of your insect <tr> <td><a href="descriptionpage.php?insect=<?php echo $row['insect_id']?>">Description</a></td></tr> You can retive the insect key with this variable on you description page: $_GET['insect']
  6. <?php $pdo = new PDO(...);$insert = $pdo->prepare(...);$update = $pdo->prepare(...); $items = array(...); foreach($items as $item) if($item->id) $update->execute(...); else $insert->execute(...); The value of $insert becomes TRUE while $update becomes a PDOStatement object.Why doesn't both of them become a PDOStatement?
  7. ckrudelux

    Project Blog

    My late second post. Have been away visiting my grand parents.I've been looking into my collection class and came up with a method making it possible to extend my SQL query. So then extending my collection class I can setup my query from the constructor using the methods: addTables, addColumns, addConditions, setColumnID and setObjectName all of these are protected methods and are only for setting up the query. This would look something like this then extending the collection class public function __construct(){ $this->addTables("`table1`"); $this->addColumns("`table1`.*"); $this->setObjectName("test"); $this->setColumnID("`table1`.id");} Then calling the fetch method which is a default method from the collection class I would get a test object returned populated with the row data from the database. If I want to extend this class I could just add an other table and columns public function __construct(){ parent::__construct(); $this->addTables("JOIN `table2` ON `table1`.id=`table2`.id"); $this->addColumns("`table2`.*"); $this->setObjectName("test2");} This made the code less repetitive then writing collection classes. But I still have to know the table name used in the previous class. At my grand parents I used my laptop since I had a clean set of the code I had to add paths etc. So I started to add setup methods to my controllers so I didn't have to write all paths and add default values every time I had a clean start. I'm not sure about how I should call these methods since I don't want to call them twice. I also know I will be adding functionality later on so I need some sort of register on what setup methods that has been called. One idea is that in the admin panel I will have a list of all the controllers which has a setup method. I would have to keep track of which one I want run and let the setup method figure out if it should run or not. This would mean that I don't need a register. What I got now is a main install file that looks for a setup methods in all files it can find but this is more of a setup all file and would probably not be as good for a single setup call. I've also started doing layout design for my admin panel. I made a Wordpress looking layout which is what I'm currently using. I'm thinking of changing some of it's design cause of the complex design of the menu buttons then hovering items that are next to the current one. Which I solved by using CSS classes set in the template by checking pre set flags of the different items in the menu. This could been preformed by CSS alone if there where a way to select something previously to the selected element. Oddly the CSS support only for the next element and not the previous one.
  8. ckrudelux

    Project Blog

    IntroductionSo I finally decide to have a go with this idea of having a project blog I'm really bad at this sort of thing and often find my self working for hours not writing a single line of comment to my code.. I don't find it necessary cause my naming often tells what it does so I don't see the point typing out the same thing the name says. But maybe I just lake the guide lines of typing comments.. read once that if you have to think twice about what a code you written does you need a comment for it. I will be doing a MVC pattern system. I've already started with this project so the first post will be covering what I've done so far. I encourage to comment any spelling or miss use of words since English isn't my main language and it would be good to get some improvements.To be clear the questions I have in my post are meant for me and I don't expect on you answering them for me. So who am I? Well I'm Andreas, I've been a member since 2008 I know I'm not the most active user I usually ask questions to small thing I don't now how to search for or then I just got completely stuck at some code error. Lets get started.So to get things in motion I'm using a class I call a Mapper class and it's task is to register paths to a controller and method. I get the path from the global $_SERVER['PATH_INFO'] variable which takes everything after "index.php" so "index.php/blog/posts/entry" would be "/blog/posts/entry". I had no intention of having any SQL queries into this class but I soon realized that I had to have a "registerMap" method to the class so I could set paths from a controller or model classes.Only problem with using this mapper method is that I can't do pages like "blog/posts/entry/page/2" in the path so they are set as normal get keys. From the index file I define paths to various places including a web root which defines the index file location compared to the server root. This is good in case you want to put this code into a sub folder. The template engine i choose to use is Smarty, you can find it at http://smarty.net, I just find it easy to use. My abstract Controller class extends the Smarty class so I can set the data form the Controller class. I added a function to tell what template folder I want to use in my view directory.Another neat thing I did was to make a plugin for Smarty what inserts the CSS files to the head so I get less request to the server. I will change that later to handle JavaScript files too. I also have a ActiveUser class that handles the current user on the site. I like this class a lot cause of the way I use sessions with it. Since we aren't allowed to throw cookies at our visitor without any permission this class only starts the session if the session cookie is set and the cookie is only set then you login on the page. I mostly like this cause I've seen complains about just this problem then reading about that new law about cookies. I think that covers the basic introduction of that I've done without going into detail of the exact code looks like to the point there I'm now. The next step is to add an admin panel where I can add and remove users. And change settings to other component. Current issueSo this is about how I handle the users which isn't the active one like say I'm logged in and i want to change someone else user type. How should I get that object in the code.At the moment I can fetch users from the ActiveUser class but this feels wrong. Cause it's not within the task that is set for the ActiveUser class. So what I think the ActiveUser should handle is hold the current user id and type and have the responsibilities to create/update/remove users. (maybe change password and type for the current user but it feels like that should be in the User class)The User class extends the Person class and contains only one extra property which is the user type.Why I choose to not have the user name in the User class is cause I hashed the user name making it more time consuming if the database got out. I also written an abstract class for collections the idea is that the class could sett properties like limit the number of objects which would be returned or the sorting order of the query "ASC and DESC" (Maybe a random order would be a great thing to add). Problem with this Collection class is that it's not fully thought through. I've written some code that uses the concept but I find my self doing the same code over and over again mostly the only thing that is different is the query to the database unless the object has child objects to be loaded. I'm sure that I should get the users from a collection class i just don't know how to complete this collection class at the moment cause the case scenarios are too many. One example is that i can load a user from the user collection but since the user is a part of a person. The person data must be loaded to the object too. Question is should I add some sort of property in the person collection class to get the query for that specific table so I can add it to my object. Also what if the object I extends has child objects and how do get them, a public method for getting that particular property data set from that person. Well I think this will be all for this time.. hope this wasn't too confusing.
  9. ckrudelux

    OOP and MYSQL

    Might have done some over thinking on how I wanted things to look like while still wanting a new point of view. I had a look at the PDO again and yes it might suite the need I'm looking for. I just couldn't place it in my thoughts and it felt wrong. Thanks for the answers I got
  10. ckrudelux

    OOP and MYSQL

    CollectPerson is storing the Person object just look in the while loop and you will see the assigning of the object to the persons property. I haven't used PDO cause I never used it before I don't really know why I should either. I understand that I could use any database I want with the same function but that isn't really needed for me at this point. Auto escaping sure it's a good thing but I could simply write my own instead of loading the hole PDO class.
  11. ckrudelux

    OOP and MYSQL

    Yes that is kind of what I do now but I fetch the array from the object collecting the result so I know that I made the query for it. I would still need to validate the data (Just haven't thought about it yet). But at least I could be sure the data is from table a and not b or isn't made up. I know it still could be over written but then it would be on purpose and not by sending the wrong array into the mix. I just feel is something else I missed something simpler I haven't thought of.
  12. ckrudelux

    OOP and MYSQL

    My issue is I don't really know any good ways to populate my objects I came up with one but did feel like it was the best way of doing it. The way of PDO is one way but feels like it doesn't scope with the idea I read about the OOP. Feels like I take out the idea of using classname/interface with the argument in a method. Yes I could use a validation on the data but could I be sure I got the right data like I can be then asking for specific classname/interface. I can't find any good articles on the web of this topics either. Just haven't seen many example on doing this. :/
  13. ckrudelux

    OOP and MYSQL

    Didn't feel like I got a pleasing answer to what I was asking. Some one else got a point of view on how to get SQL data into the objects?
  14. ckrudelux

    Renaming files

    $newfile = explode(".",$originalimg);array_pop($newfile);$newfile = implode(".",$newfile) . ".png";rename($originalimg, $newfile);
  15. ckrudelux

    Renaming files

    What works until someone has .png in the filename and not as an extension. Try with explode and take away everything after the last dot.
  • Create New...