tags:

views:

69

answers:

3

No ORM. All I know is that I have PHP 5+ and adodb. From those two, how can I use MVC? I cannot use other frameworks and I"m not asking that someone build be anything from scratch (I want to learn!). But how would I start off here? I know how to mix things incorrectly classic asp style. What I don't know how to do, on a very very basic level is to do MVC. Say I had a model which is just some adodb and SQL, how do I get that to go from my "model" to my view? Or how do I call anything from my controller since I don't have an ORM to call?

Can someone give me something concrete? I am hoping this is the basis of a future CMS.

Thanks

A: 

Basis of a future CMS? Why not start with one of the zillions of open source php CMS projects and branch it to support your needs?

If you want to learn MVC paradigm, learn a php MVC framework. Learning 2 is even better.

If you want to learn how a CMS system is built, study the source code from an open source one. Then you'll be ready to roll your own and you'll be quite enlightened.

burkestar
Because I want to learn myself. I'm not trying make the next best CMS just our next cms or paradigm. I finally have the carte blanche to learn and I don't want to wasted it.
johnny
A: 

You can code anything with a MVC style on your own just by separating the view files (using Smarty or plain old PHP files) from your models (Objects which map to your database) and your controllers (PHP files which do the "crunching"), but I would recommend a PHP framework which already does the heavy lifting for you.

Zend = zend.com *arguably the industry standard

CakePHP = cakephp.org *very slick

Kohana = kohanaframework.org *requires php5+, based off of CodeIgniter

CodeIgniter = codeigniter.com *requires php4+

I am a big fan of Kohana which just released a new version. Kohana has a built in ORM tool, a view object and an already built method for controllers to handle action requests.

I know some folks can code it. I can't. That's what I'm trying to learn I for the moment I don't wan tot use anyone else's framework no matter how superior there's will be to mine. To make a long story short none of them do exactly what I want so I need to build my own.
johnny
Another framework I just found: Yii - yiiframework.com. The code in gordon's post above is quite simply exactly what Cake/Kohana/CI/Yii/Zend do for you. They just give you helper methods to make your life easier. That said, you can roll your own as he explains.
+2  A: 

There is nothing magical about MVC. It's purpose is to split user interface interaction into three distinct roles. The important separation is that between Model and Presentation layer. The presentation layer consists of Controller (handles and delegates request from the UI to the model) and View (renders Model data).

Your model is your core application. It is likely layered itself, for instance into a Data Access layer (your AdoDB stuff), a Domain Model and a Service Layer. How you organize the Model is really up to the application you want to build. The important thing with MVC is to keep the model independent from the presentation. Your application should be able to solve the problem it was written for without the UI.The UI is just one interface on top.

Basically, as long as your controller is kept thin and does this

class SomeController
{
    public function someAction()
    {
        $input   = filter_input(/* ... */);
        $adoDb   = $this->getModel('MyAdoDbClass');
        $newData = $adoDb->doSomethingWithInput($input);
        $this->getView()->setData($newData);
        $this->getView()->render();
    }
}

and not this

class SomeController
{
    public function someAction()
    {
        $input  = filter_input(/* ... */);
        $adoDb  = new AdoDb; 
        /*
            all the code that belongs to doSomethingWithInput
            ...
        */
         echo '<html>'; 
        /*
            all the code that should belongs to the View                 ...
         */
    }
}

you are fine. Like I said, there is nothing magical about. You gotta keep 'em separated.

I suggest you have a look at other frameworks to see how they approach MVC. That's not to say you should copy or use them, but try to learn how they go about MVC. Also have a look at Rasmus Lerdorf's article The no-framework PHP MVC framework

Gordon
thank you. But on the "this->getModel" and so one where does "this->" point to? There's not other class that I see. I know from experience it is pointing to my model like in CodeIgniter but I never see the glue...what makes it so you can do things like $-this->getView()....
johnny
@johnny `$this` refers to the instance of `SomeController`. Nothing magical about that either. You might want to have a look at [what does this mean within a class definition](http://stackoverflow.com/questions/3776696/what-does-this-mean-within-a-class-definition/3776736#3776736)
Gordon