0
votes

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?

2
first things first, do the quickstart in the ZF docs and then do the ZF 1.11 tutorial at Akrabat.com When you've got that far, ask again. Your question will be better, and you'll get better responses. - RockyFord

2 Answers

1
votes

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...

1
votes

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';

  }