Jump to content

seddonym

New Members
  • Posts

    4
  • Joined

  • Last visited

    Never

Profile Information

  • Gender
    Not Telling

seddonym's Achievements

Newbie

Newbie (1/5)

0

Reputation

  1. A few months ago I realised that I would be best off producing a site using an MVC framework but got pretty bogged down in how to implement one. The advice I would give is: don't bother trying to write one. At least not yet. The first thing you should do is use someone else's MVC framework. There are a few around and they are designed to give you easy (ish) ways of creating MVC based sites. I find it difficult to believe that someone who's never made an MVC framework before would come up with a better one than an existing one that is already out there and is tried and tested. The only one I've used is CodeIgniter, which is apparently a good choice for beginners. Cake is also very popular. All they are (and I'd wish I'd known this earlier) is a load of php files in a prepackaged directory structure that you upload onto your server. You then add php files to the correct directories, according to the format decided on by that particular package. For example, with CodeIgniter you put controllers in the 'controller' directory, models in the 'models' directory, views in the 'views' directory. (Who would've thought...) You can also edit settings in various configuration files. CodeIgnitor's documentation is a pretty good way into the whole thing. You can start using it without understanding the nuts and bolts of how MVC works (just how it is used) but you can look at all the source code if need be. Hope that's useful.
  2. I was asking a similar question to you a few months ago. With the journey I have since taken I think it is definitely worth getting a good working knowledge of object oriented PHP, even as a beginner. Recently I made the jump into OOP programming through the book PHP5 Objects, Patterns and Practice by Matt Zandstra. The first part is particularly good at giving you confidence about how everything works - it assumes you understand procedural PHP but tells you everything about OOP PHP. It's also really good at giving you an idea about why OOP is so powerful. The other thing I would recommend is making yourself aware of using coding frameworks such as PHP Cake or Codeigniter. These are both PHP applications that you can use to write more complex sites, and they work using OOP. To use them, you need to be equipped with the basics of OOP. Using them didn't make much sense to me until I had read the above book. Good luck!
  3. Thanks for your suggestions - I've had a look at the MVC pattern but it all seemed a bit too complex for what I want to do, at least for now. Perhaps something to learn for later, although a pity I wasn't able to find a really straightforward introduction to setting up a bare-bones MVC site. What I have ended up doing was implementing a rather half-hearted attempt at OOP. I have two classes, currentPage and user. I also have a subclass of user called currentUser, which I have implemented as a 'singleton'. This means I can easily access the currentUser properties globally using, for example: currentUser::singleton()->loggedIn or currentUser::singleton()->userName Everything else is procedural. On second thoughts, however, I can't really see the advantage of using these classes intermittently and will probably end up going back to a fully procedural model, using the user and page properties as global variables. If only there were a way of using include within class definitions so you could split the code up into different files, for ease of editing...
  4. Hi I'm trying to convert a rather messy function based site into a cleaner object-oriented version (but I'm new to OOP). My basic strategy was to have a 'page' class that I would then instantiate on each page, for example:- friends.php <?php require_once('functions/mainfunctions.php'); $currentPage = new page; $currentPage->title = 'Friends Page'; $currentPage->membersOnly = true; $currentPage->begin(); $currentPage->displayFriendsList(); $currentPage->displayMenu(); $currentPage->displayFooter(); ?> As you can see there are certain properties I would set at the beginning of the page. I then call begin() which deals with access (linking to mysql database) and outputs the page headers. There are page-specific display methods next, and finally a method which displays the footers. The methods shown in the page all call lots of other methods so everything is very modular. My original intention was to create a lot of methods all within the page class definition (access methods, display methods, error handling methods etc.). I did this because I wanted them all to have access to the page's properties (which include things like the current User) via $this->[propertyname]. I wanted to put them into separate files and then use include() to put them into the one large class - but I now discover that isn't possible (and probably making one huge class is bad programming practice anyway). I could just have all the code in one file but that's very difficult to edit and strikes me as the wrong solution. Really what I need is a simple pointer on a good way of structuring an OOP site so that everything is kept very modular, (and in different files) but all the properties of the page are available at all times. Should I be using several classes, scope resolution operators, global variables, subclasses... Perhaps there is a good tutorial on this but I haven't been able to find one that specifically gives a simple overview of a site. Thanks enormously!
×
×
  • 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.