[Solar-talk] Where to save the models and where is the Model documentation?

Paul M Jones pmjones at solarphp.com
Tue Jul 4 15:41:57 PDT 2006


Hi Stuardo,

Today is a holiday in the US, so this will probably be too short.   
Having said that:


> Ok, I understand that in a MVC system, the Model is the Data-Layer,  
> right?

Yes,

> It should abstract the database communication, am I right?

and yes.  :-)


> Ok, I'm trying to write a DevelSystems_App_CMS to start learning Solar
>
> I understand that the DevelSystem/App/CMS.php is the controller in  
> the MVC,
> the Views are inside DevelSystems/App/CMS/View, but where are the  
> models for
> this app?

You would put them outside the app itself.  For example, if the table  
is named "Content", you might put it in DevelSystems/Model/ 
Content.php (and the class name would match the path).  A model *can*  
be extended from a table, but it doesn't *have* to me.

The main reason for keeping models separate from apps is that path  
names start to get too long.  E.g., DevelSystems/App/Model/ 
Content.php might be ok, but the locale files would be in  
DevelSystems/App/Model/Content/Locale/es_ES.php, and that's a bit too  
deep I think.

Also, you are likely to need the same models across different apps,  
so it wouldn't (in theory) make sense to keep it with just the app.

Finally, if other apps from other vendors need access to the data  
directly, they shouldn't have to go through the app, they should be  
able to refer to the model itself, so again it doesn't make sense (in  
theory) to keep it with the app.


> My DB is only 1 single table
> pages (id, parent, en_name, en_body, es_name, es_body)   So, I  
> would like a
> Model to access the pages and create a menu wit all childs...  but  
> I do not
> undersand where to create it and how to start it (what class should  
> it extend
> from)

You extend it from Solar_Sql_Table.  You then override the _setup()  
method to define the table schema.In _setup(), use $_col[] to define  
your columns, and $_idx[] to define indexes.  (The id, created, and  
updated fields will automatically be created for you.)  For examples  
of this, see Solar_Model_Areas, _Nodes, and _Tags.

The first time you instantiate the model object, Solar_Sql_Table  
looks to see if that table exists, and creates it for you if it's not  
already there.

I know this is not a lot of help, but it should get you started; let  
us know how it goes for you.



--

Paul M. Jones  <http://paul-m-jones.com>

Solar: Simple Object Library and Application Repository
for PHP5.   <http://solarphp.com>

Savant: The simple, elegant, and powerful solution for
templates in PHP.   <http://phpsavant.com>




More information about the solar-talk mailing list