Jump to content

Recommended Posts

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.

Edited by ckrudelux
  • Like 1
Link to post
Share on other sites
  • 2 weeks later...

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.

Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...