0

I'm new to Zend Framework. I've been following book "ZendFramework - A Beginners Guide". in the 4th chapter, they start using Doctrine. The thing is that I'd like to use Zend's built-in functionality with database interactions.

I've searched the web and watched couple of tuts. Well I couldn't find the right (for me) solution.

in all tuts, everyone is using standard Zend's structure. I'd like to integrate my Modules. So I have a file structure like this:

application
   /modules
      /moduleName
          /controllers
          /models
          /views

I have set up the routes in application.ini for controllers and views like this:

; /articles/* route
resources.router.routes.articles.route = /articles
resources.router.routes.articles.defaults.module = content
resources.router.routes.articles.defaults.controller = articles
resources.router.routes.articles.defaults.action = index  

Now I tried to load-up my models so I start interacting with the tables in Mysql.

in my controller named ArticlesController.php I created the class Content_ArticlesController and in there I have:

  public function indexAction()
  {

      $model = new Content_ArticlesModel();
      $this->view->modelHi = $model->there;
      $this->view->hello = 'Hello there';

  }

As you might guess Content_ArticlesModel is my class that extends Zend_Db_Table_Abstract class. in there I have a public function modelHi() that I'd like to call from my Controller to pass the data from the model to the view.

Can someone help me do this in the right way? how should I correctly load-up my models for my modules? and maybe you could link some good article on working with database based on some example.

EDIT: Ok, I had this really studip error in my Controller but it's ok. Anyways the problem is that when Zend loads-up my controller it displays: Fatal error: Class 'Content_ArticlesModel' not found in S:\xampp\htdocs\testsite\application\modules\content\controllers\ArticlesController.php on line 12

The issue is my Zend can't locate/doesn't know where to find the models of my module that I'm trying to reach from my controller.

I want to know how should I make Zend see and use my models?

mrGott
  • 1,066
  • 3
  • 18
  • 53
  • first things first, do the [quickstart](http://framework.zend.com/manual/en/learning.quickstart.intro.html) in the ZF docs and then do the ZF 1.11 tutorial at [Akrabat.com](http://akrabat.com/zend-framework-tutorial/) When you've got that far, ask again. Your question will be better, and you'll get better responses. – RockyFord May 21 '12 at 04:24

2 Answers2

1

Why not just call your public modelHi() method in your controller

Update: If your module name is 'content' , then your model should be located

application/modules/content/models/ArticlesModel.php

then do the following

public function indexAction()
  {

      $model = new Content_Model_ArticlesModel(); //name of class
      $this->view->modelHi = $model->modelHi();
      $this->view->hello = 'Hello there';

  }
Mr Coder
  • 8,169
  • 5
  • 45
  • 74
  • @beginner that's what I did, but it says Fatal error: Class 'Content_ArticlesModel' not found in S:\xampp\htdocs\testsite\application\modules\content\controllers\ArticlesController.php on line 12 ... Simply my Zend doesn't know about my model. So I have to load it up - that's what I can make work. – mrGott May 21 '12 at 06:08
  • @beginner do I have to set up application.ini or smth else? it doesn't work the way you suggest – mrGott May 21 '12 at 23:06
1

You should make configuration in application.ini file for modeule and view

resources.modules = 

resources.view[] =

Also you should make bootstrap file inside your module

class Content_Bootstrap extends Zend_Application_Module_Bootstrap {
 }

Also you should ensure that the name of your modulel folder is small letter "content"..

After making these configuration, you will be able to call model inside controller...

palAlaa
  • 9,500
  • 33
  • 107
  • 166
  • do I have to write something in the new bootstrap? I just added Bootstrap.php in the application/modules/content folder and added config lines to application/configs/application.ini file.. I think I'm not doing it right way... – mrGott May 21 '12 at 07:46
  • @Mikey, No the bootstrap file is empty, but ensure from case sensitive of module folder name and the name of class inside bootstrap – palAlaa May 21 '12 at 08:12
  • this worked... Can you tell me in your own words what does Bootstrap.php do? I know it somehow manages and wraps the handling of application (maybe I'm somewhere close). What did it change in my case, though it's empty?? – mrGott May 21 '12 at 23:11
  • 2
    @Mikey the class it extends take the directory name of module folder and use it to setup Module Resource Autoloader . – Mr Coder May 22 '12 at 07:19
  • @Mikey, the bootstrap file set up the namespace of each module and its Autoloader methods in order to define objects inside other classes.. – palAlaa May 22 '12 at 09:24