Jump to content

ryanlball@gmail.com

New Members
  • Posts

    8
  • Joined

  • Last visited

    Never

Everything posted by ryanlball@gmail.com

  1. It looks like I found most of what I'm looking for. It turns out that when you extend Zend_Db_Table_Abstract you also inherit the adapter that is automatically created in the master .ini file on creation (see original post). This means that I don't need to write a single line of additional code in order to access the Databse. Pretty sweet. So, here's an example. Let's say that I have a model that extends Zend_Db_Table_Abstract like so: [pre]'application/models/Tablename.php' class Tablename extends Zend_Db_Table_Abstract { /* Assuming the table name matches 'Tablename' (the name of the class) and the table id is 'id' you don't need to do anything else in order to take advantage of the basic methods built in to Zend_Db_Table_Abstract. This is pretty sweet. */ // Otherwise you can change set the table name and the primary id like so: protected $_name = 'theActualTableName'; protected $_id = 'tablename_ID'; }[/pre] So, I just store my models like this in the models folder. Currently there is no great way to auto load these models. I have my own little way of doing things but for now I'll just make sure that my 'models' folder is in my include_path and include the class directly before calling it. So, when I'm ready to call the functionality of working with that table I just include the file and create the class. Let's say I want to work with that table in an action controller. I imagine I can also do this in an action helper or view helper, even the view or another model. It's probably best to keep the controllers slim by accessing this in another model but for now I'll just access it in the index action controller like so: [pre]class IndexController extends Zend_Controller_Action { public function indexAction() { include_once 'Tablename.php'; $tableName = new Tablename(); // The result is stored in a multidimensional associative array. $results = $tableName->fetchAll(); // 'fetchAll()' is one of several inherited methods, awesome! // Access the data and send to view. foreach($results as $row){ $toView .= $row['fieldKey'].'<br />'; } $this->view->foo = $toView; // Send the information to be displayed by the view. } }[/pre] For more on the specifics of Zend_Db_Table_Abstract go to: http://framework.zend.com/manual/en/zend.db.table.html.
  2. Rather than create a db connection for each model I imagine there is an easy way to bootstrap one persistant connection across all models that need it. I've already registered the db resource in the ini file. that portion of the file looks like this: resources.db.adapter = "PDO_MYSQL" resources.db.isdefaulttableadapter = true resources.db.params.dbname = "dbname" resources.db.params.username = "username" resources.db.params.password = "secure" resources.db.params.hostname = "localhost" resources.db.params.charset = "UTF8" So, I'm hoping this will automatically set up the db connection and if so how do I access it from the front controller? Any thoughts on this specifically would be appreciated. I'd also be very interested to see different ways to solve this problem. Thank you!
  3. I see. Thank you for your help on this!! I'll probably just do something similar. Thank you again!
  4. I see. So it sounds like auto including files needs to be within a name space. Is there a way to auto include classes that are simply in the include_path but not necessarily in a name space?
  5. It seems like a simple thing. My understanding is that as long as my library follows the same PERL naming convention and are placed in the include_path the classes should autoload. So, specifically I want to autoload my models so I've included the 'application/models' in my include path like so: set_include_path(implode(PATH_SEPARATOR, array( get_include_path(), realpath(APPLICATION_PATH . '/../library'), realpath(APPLICATION_PATH . '/models'), ))); This is almost identical to the default bootstrap file created by Zend_Tool. Now, I have a class called 'ClientModel'. In my index controller and action I'm trying to create a ClientModel object like so: class IndexController extends Zend_Controller_Action { public function init() { /* Initialize action controller here */ } public function indexAction() { $client = new ClientModel(); } } The model class looks like this: class ClientModel extends Zend_Db_Table_Abstract { // .. Model code } Any ideas why this class is not auto loading? I also have my own library that follows PERL naming that also doesn't load. That library is located in the 'library' folder where the Zend Framework library is located. What's even more strange is that when I include the file directly as if it were in the model file, it loads correctly. In other words, I have every reason to believe that the 'models' include directory is valid. Also, Zend Library components load so it seems the autoloader is working. Maybe there is something about the autoloader I don't know about? Any thoughts are much appreciated!
  6. Oh, I see. That makes sense. So, in a sense, when I create an object $obj = new Class() that object is being returned in a similar way as 'return $this;'. Thank you, again for your response. That's very kind.
  7. Thank you for the answer. I understand using $this->whatever or $this->whatever($blah) but the difficulty I'm having is that there is nothing after the word '$this'. It's not pointing to anything.
  8. Hello! In trying to understand Zend Framework a little better I've been going through some of the core library code. I've been tracing the general path from Zend_Application. I've noticed several times that a method simply returns 'return $this'. I've never seen that before. It's really cool and I'm excited to understand what it means. Below is one example: found in Zend_Loader_Autoloader public function setAutoloaders(array $autoloaders) { $this->_autoloaders = $autoloaders; return $this; } I really appreciate this help!
×
×
  • 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.