Changeset 2951
- Timestamp:
- 09/27/08 17:43:42 (8 weeks ago)
- Location:
- documentation/trunk
- Files:
-
- 4 modified
-
stages/stage2/app/lib/model/BlogBaseModel.class.php (modified) (1 diff)
-
stages/stage3/app/lib/model/BlogBaseModel.class.php (modified) (1 diff)
-
topics/creating-models.dita (modified) (2 diffs)
-
topics/examples.xml (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
documentation/trunk/stages/stage2/app/lib/model/BlogBaseModel.class.php
r2723 r2951 12 12 protected function getPdo() 13 13 { 14 // The connection parameters are configured in app/config/databases.xml 14 15 return $this->context->getDatabaseManager()->getDatabase()->getConnection('blog'); 15 16 } -
documentation/trunk/stages/stage3/app/lib/model/BlogBaseModel.class.php
r2723 r2951 12 12 protected function getPdo() 13 13 { 14 // The connection parameters are configured in app/config/databases.xml 14 15 return $this->context->getDatabaseManager()->getDatabase()->getConnection('blog'); 15 16 } -
documentation/trunk/topics/creating-models.dita
r2723 r2951 29 29 methods: one to return the contents of the front page (a list of the most 30 30 recent posts) and one to find a specific post given its ID. To do this, 31 you need to create a new Model! The project configuration system eases 32 your job immensely:</p><p><screen>bloggie$ <userinput>agavi project-model-create</userinput> 31 you need to create a new Model. The project configuration system eases 32 your job immensely:</p><p> 33 <screen>bloggie$ <userinput>agavi model-create</userinput> 34 35 Module name: <userinput>Public</userinput> 33 36 34 37 Model name: <userinput>Posts</userinput> 35 [copy] Copying 1 file to /home/nfontes/bloggie/app/models</screen>You now 36 have an empty Posts Model class ready to be populated with application 37 logic:</p> 38 <codeblock conref="examples.xml#stage2-posts-model" class="php"/> 39 <p>The Posts Model contains two very simple methods. The first 38 [copy] Copying 1 file to [...]/app/modules/Public/models</screen> 39 </p> 40 <p>You now have an empty Posts Model class ready to be populated 41 with application logic:</p> 42 <codeblock conref="examples.xml#stage2-posts-model" class="php"/> 43 <p>Note that in the base Model class for Bloggie 44 (<filepath>app/lib/models/BlogBaseModel.class.php</filepath>) we 45 have a <apiname>getPdo()</apiname> method which we presume all of our future models 46 would want to use:</p> 47 <codeblock conref="examples.xml#stage2-base-model" class="php"/> 48 <p>The Posts Model contains two very simple methods. The first 40 49 is <apiname>findPostById</apiname>, which accepts an ID parameter 41 50 and returns corresponding post data as a single dimensional … … 45 54 posts themselves. Both methods obtain the connection from Agavi's 46 55 database manager, perform an SQL query against it and return the 47 results.</p> <p><note type="important">We will soon discover that48 we need more than one Model to handle posts!</note></p><p>As we49 already have some dummy data in the database, we can now proceed50 to make working pages that utilize our newModel.</p></section>56 results.</p> 57 <p>As we already have some dummy data in the database, we can now 58 proceed to make working pages that utilize our new 59 Model.</p></section> 51 60 </body> 52 61 </topic> -
documentation/trunk/topics/examples.xml
r2748 r2951 41 41 </configuration> 42 42 </configurations> 43 </codeblock> 44 <codeblock id="stage2-base-model"> 45 /** 46 * The base model from which all project models inherit. 47 */ 48 49 class BlogBaseModel extends AgaviModel 50 { 51 /** 52 * Return the PDO resource needed to access the blog database 53 * @return PDO 54 */ 55 protected function getPdo() 56 { 57 // The connection parameters are configured in app/config/databases.xml 58 return $this->context->getDatabaseManager()->getDatabase()->getConnection('blog'); 59 } 60 } 61 62 ?> 43 63 </codeblock> 44 64 <codeblock id="stage2-posts-model">

