tags:

views:

232

answers:

8

ok i think i am pushing my self to far here, im createing a project in my own mvc even i dont know what mvc its self,

<?php    

class init
    {
        function __construct()
        {
            $this->enviroment();
            $this->start();
        }

        function enviroment()
        {
            /* Required Classes */  
            require_once( ROOTPATH . BOOTSTRAP . REDENGINE . '/class.debug.php');
            require_once( ROOTPATH . BOOTSTRAP . REDENGINE . '/class.theme.php');
            require_once( ROOTPATH . BOOTSTRAP . REDENGINE . '/class.url.php');
            require_once( ROOTPATH . BOOTSTRAP . REDENGINE . '/language/class.lang.php');
            require_once( ROOTPATH . BOOTSTRAP . REDENGINE . '/class.sessions.php');
        }
        function start()
        {   
            /* Start Classes */
            $uSys = new Urlsystem;
            $fragments = $uSys->getFragments();
            $tSys = new ThemeSystem;
            $lSys = new LanguageSystem;
            $sSys = new Sessions;   

            /* defineing APPVIEWS & APPCONTROLLER */        
            define( 'APPVIEWS', '/appviews' );
            define( 'APPCONTROLLER', '/appcontroller' );

            if ( empty($fragments) )
            {
                require_once( ROOTPATH . APPCONTROLLER . '/app.home.php'); /* default app controller page */
                require_once( ROOTPATH . APPVIEWS . '/view.home.php'); /* default app views page */
            }

            if ( !empty($fragments) )
            {
                // Start ENGINE
                if ( !file_exists(ROOTPATH . APPCONTROLLER . '/app' . $fragments . '.php') &&
                     !file_exists(ROOTPATH . APPVIEWS . '/view' . $fragments. '.php')
                ) {

                            if ( file_exists(ROOTPATH . APPCONTROLLER . '/app.404.php') &&
                                 file_exists(ROOTPATH . APPVIEWS . '/view.404.php')
                             ) {
                                require ROOTPATH . APPCONTROLLER . '/app.404.php';
                                require ROOTPATH . APPVIEWS . '/view.404.php';
                            }
                            else {
                                echo "NO 404 APP || VIEW";
                            }
                }           
                if ( file_exists(ROOTPATH . APPCONTROLLER . '/app' .  $fragments . '.php') ) 
                {
                    require ROOTPATH . APPCONTROLLER . '/app' . $fragments . '.php'; // load application

                    if ( file_exists(ROOTPATH . APPVIEWS . '/view' .  $fragments . '.php') ) {
                        require ROOTPATH . APPVIEWS . '/view' .  $fragments . '.php';// load view
                    } 
                }
                // End ENGINE
            }       
        }
    } ?>

ok as you see my front controller, so i know its failing, i just notice my fail after i nearly finish my project, especialy when i need to do www.someurl.com/?$getuser or www.someurl.com/myname or a user.

anyway my question is when do we really need MVC for php? im looking at facebook, etc

they still use the ?this=blabla get so they are not MVC , is that right ? anyway im still confused how facebook does www.facebook.com/myname without it. ( htaccses ? )

if they dont use mvc then when do we really need it ?

note* iv read many thread about when use mvc, but i haven't found one in my problem, if there is please leave a comment so i can read :)

Thanks a lot.

+2  A: 

MVC is an architectural pattern focused on separation of concerns; the URL's have nothing to do with it.

URL's are handled by the server. If it's Apache you are using, set up mod_rewrite.

That being said, you might want not to reinvent the wheel, but look at options available out there, there are plenty of MVC-oriented PHP frameworks. Find one that you like and can be productive in and use it.

NullUserException
It helps to understand what MVC is and how it works before using a framework that does it for you. Implementing a simple MVC pattern is a good way to figure out how it works, imo.
banzaimonkey
A: 

You are really making it hard on yourself by attempting to writing your own mvc. (You are not doing it by manipulating the URL scheme). While it is a good educational experience to write one yourself, you will not get the level of quality and the benefits of the MVC pattern by reinventing the wheel.

Write your app in symfony, zend, codeigniter cake or any of the good open source MVC frameworks out there. When you get a feel for how it should work, then you should create your own for fun.

These frameworks exist to make your projects faster to code and more maintainable.

Byron Whitlock
It's [symfony](http://www.symfony-project.org/)
NullUserException
:| , btw is it really needed ? when can i tell when mvc is really needed ?
Adam Ramadhan
@Adam Ramadhan MVC is a design pattern. Each design pattern has its own theoretical uses, and implementation details will usually differ from the pattern in some way. The only way to know whether you would benefit from MVC is to understand what MVC is and how it relates to your project.
banzaimonkey
+1  A: 

you might consider starting by using one of the many different MVC frameworks out there, such as CodeIgniter or cakePHP. These frameworks have bene developed by many pople and refined over a period of time. MVC is not necessary, but once the boilerplate is established, creating web applications is very fast.

Scott M.
I would agree with this. Using cakePHP hides away lots of the stuff that you shouldn't have to worry about so you can just get your work done.
speshak
+2  A: 

I think you're confusing MVC with query params. The two are not necessarily linked, though it is true that the more popular PHP MVC frameworks do mask the params by using mod_rewrite or an equivalent method.

MVC is simply a way to keep your presentation logic separate from your business logic. Think of it this way: if you have a site using MVC, you can easily create a mobile phone version by simply changing the views based on the browser, your site's logic doesn't need to change, just the HTML that is sent to the client.

speshak
+5  A: 

I believe you are confused between MVC and having RESTful URL scheme (http://en.wikipedia.org/wiki/Representational_State_Transfer#RESTful_web_services).

MVC is just a coding pattern that separates entities and modules. Like Application Logic from GUI Templates while The URL pattern is a different thing altogether. URLs are just to access a Web Resource. MVC frameworks like CodeIgnitor can still give you 'ugly' URLs if you do not work it out with .htaccess

AJ
I think I forgot to mention mod_rewrite but others have done that already.
AJ
+2  A: 

It seems that your question is confusing two different topics together. Model View Controller(MVC) and pretty URLs.

Model View Controller is a design paradigm which allows you to separate your logic(model), your templates(views), and your directing input/output(controller).

Pretty URLs on the other hand, allow for redirecting urls based on format rules(typically .htaccess rules).

Model-View-Controller - design paradigm information.

Pretty URLs tutorial - implementation of using Apache's mod_rewrite.

mod_rewrite - information on what a rewrite engine is.

David Young
so im on the right track ?
Adam Ramadhan
MVC is a good pattern to use for many reasons, creating your own from scratch though may not be the best approach. I would say look at the popular PHP frameworks to see how they approached the issues you're facing. http://framework.zend.com/, http://cakephp.org/, and http://www.symfony-project.org/ are all very popular frameworks.
David Young
+1  A: 

When to use... All the time, is a good practice.

Personally, my choice: Symphone and Doctrine can easier to write big applications by team. But began with CodeIgniter.

HWTech
The PHP framework is called "Symfony," the actual word is "Symphony."
NullUserException
are you sure about all the time ? hmm facebook still use www.facebook.com/editprofile.php so i assume that they are not a mvc ? , maybe becouse of the hiphop compiler ? ok maybe im stupid .
Adam Ramadhan
I telling about principle of web-development. I'm quite sure that they use Control-Model-View separation.
HWTech
+2  A: 

Saving your code, HTML, and data in different folders is the most basic way of structuring your application - and that's the primary reason for implementing MVC: organization.

The other design patterns present in most frameworks supplement MVC, and they promote code reuse, rapid development, etc. But you can do the latter even without MVC - all it takes is a code library! Most frameworks utilize the MVC design pattern, but MVC != frameworks.

Some frameworks require you to tweak Apache (Lighty, Nginx, etc) to make it a framework extension. Pretty URLs are just a way of presenting input data (view) that are consumed by the controller so the latter can route to the appropriate handler. Seen in this light, .htaccess is an integral part of MVC for such frameworks.

Before you plunge deeper into your project, it helps to do a little more research. Most frameworks have taken the convoluted approach to MVC, which have led many to confusion. Fat-Free Framework uses a more direct and easier-to-follow path.

stillstanding
love the f3. can we call that an mvc?
Adam Ramadhan