Welcome, Guest. Register Now!
   
Mark Forums Read Mark Forums Read Mark Forums Read


Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 05-13-2008, 06:40 AM
Junior Member
 
Join Date: May 2008
Posts: 2
Default Newbie question

Hi,

I have a pretty large online-store project ahead of me. I have the next 2 months to develop it and am starting now; I am confident I can finish this in time with my 'old' coding style.

However, I have installed and gone through the 'getting started' tutorial of Zend, and can see how useful and powerful the framework can be. However I can also see that more complex tasks are (at the moment) beyond me and I really need to spend a lot of time working with the framework to understand how to implement different functionalities. For example, I am only trying to learn now how to build a basic form and process the data (using the MVC logic), I can't imagine when I will know how to connect to a database and implement a complex Ajax-based products detail page with shopping cart. So, from what I can see, Zend sounds so useful, but I will probably have a significant learning curve if I want to build this particular project under a framework, since frameworks in general are new to me.

Therefore, my question is this - can I "keep" Zend installed on my server, and use its capabilities for the simpler tasks (e.g. building a form).. but at the same time, I will include my own class file from the index.php file (this class file will be a php file that has all the small functions that I've used over the past few years and find useful for my projects).

Therefore, I will write some extra code in index.php to call my own class file and generate an object,
[CODE[include('../my_general_class_file.php');
$conn = new MyGeneralClassFile;[/code]

The $conn variable will therefore be available for my scripts, whether these scripts will be developed in the way I'm used to (i.e. using php include files that will be included via index.php) or if necessary the $conn variable will also be able to be accessed as a global variable in the Zend class files that I build in the future.

Does anyone have any comments on this or any recommendations? The point is, I don't have the time to fully work on Zend for this particular project, yet I want to "keep" Zend installed and ready so that I can use it for particular tasks for learning, eventually using more and more of the framework as I become more familiar with it.

Many thanks!
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #2 (permalink)  
Old 05-15-2008, 03:03 PM
Junior Member
 
Join Date: May 2008
Posts: 10
Default

Yes, using specific components of the Framework is very easy. It is literally as simple as including the class.

For example, using Zend_Db:

PHP Code:

// set include path to where framework is installed
set_include_path('../library' PATH_SEPARATOR get_include_path());  



// require the class
require_once 'Zend/Db/Adapter/Pdo/Mysql.php';


// initialize
$db = new Zend_Db_Adapter_Pdo_Mysql(array(
    
'host'     => $dbhost,
    
'username' => $dbusername,
    
'password' => $dbpassword,
    
'dbname'   => $dbname
));

// Done! We now have a Zend db adapter for use

$result $db->fetchAll($db->select()
      ->
from('some_table')   
      ->
where('product_id > ?'4
      ->
order('product_name ASC')
);
// so on and so forth.... 
We can go farther, including more and more, here, I'll grab the Zend_Db_Table stuff:
PHP Code:
require_once 'Zend/Db/Table.php';
require_once 
'Zend/Db/Table/Abstract.php';


// declare a model
Zend_Db_Table::setDefaultAdapter($db);
class 
Events extends Zend_Db_Table_Abstract
{
    protected 
$_name 'events';
}

// Here's a call using the new Model we just set up
$events = new Events();

$event $events->fetchRow($events->select()->where('id = ?'5); 

This is all done without using the Framework for MVC or anything, and this is, of course, by no means limited to the Db classes, you can do this for anything and everything in the Framework.


My recommendation for your particular case, would be to build the project in the way with which you are comfortable. Don't use the Framework for MVC, etc. But, use some of it's components that you may find useful.

Last edited by jasonw : 05-15-2008 at 03:09 PM.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT. The time now is 10:44 PM.