Search code examples
phpzend-frameworkzend-dbsocialengine

Social Engine get data from database and print it


I tried to create a module in SE4, and followed a tutorial (How to create a model and get data from MySQL to display in SE4) but can't seem to make my database output print out in my view. Here's code:

Database dump, i used engine4_ prefix, as all my other tables are named that way

-- phpMyAdmin SQL Dump
-- version 2.11.11.3
-- http://www.phpmyadmin.net
--
-- Host: localhost
-- Generation Time: Aug 14, 2012 at 11:32 AM
-- Server version: 5.5.23
-- PHP Version: 5.3.14

SET SQL_MODE="NO_AUTO_VALUE_ON_ZERO";

--
-- Database: `xyzeljubko`
--

-- --------------------------------------------------------

--
-- Table structure for table `engine4_zki_pitanja`
--

CREATE TABLE IF NOT EXISTS `engine4_zki_pitanja` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `test` varchar(20) NOT NULL,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB  DEFAULT CHARSET=latin1 AUTO_INCREMENT=2 ;

--
-- Dumping data for table `engine4_zki_pitanja`
--

INSERT INTO `engine4_zki_pitanja` (`id`, `test`) VALUES
(1, 'Stringcina');

My module is named zki, and here are two models I created, /Zki/Models/pitanje.php

<?php 
    class Zki_Model_Pitanje extends Core_Model_Item_Abstract
    {
        protected $_owner_type = 'user';
    }
?>

and model Zki/Models/DbTable/pitanja.php (plural)

<?php 
    class Zki_Model_DbTable_Pitanja extends Engine_Db_Table
    {
        protected $_rowClass = 'Zki_Model_Pitanje';
    }
?>

as of controller, here is Zki/Controllers/pitanjeController.php

<?php 

    class Zki_PitanjeController extends Core_Controller_Action_Standard
    {
        public function indexAction()
        {
            // default action
        }

        public function viewtestAction()
        {
            // uzmi tabelu
            // getDbTable(TABLENAME, MODULENAME);
            $table = Engine_Api::_()->getDbTable('pitanja', 'zki');

            // neki filtering, select i to
            // docs: http://framework.zend.com/manual/en/zend.db.select.html
            $select = $table->select(); // ->where("user_id = $id", 1)->order('creation_date');

            // dohvati podatke
            $result = $table->fetchAll($select);
            $this->view->pitanja = $result;
        }
    }
?>

and finally my view Zki/Views/scripts/pitanje/viewtest.tpl

<?php 
    foreach($this->pitanja as $pitanje) {
        echo 'Id pitanja: ' . $pitanje->id . ' and test string is ' . $pitanje->test . '. Endline. <br/>';
    }
?>

But doesn't seem to work. I'm not sure how to debug this problem, but seems to be trivial. Can anyone help me realize where I wen't wrong on this one?


Solution

    1. Have you made id column primary?
    2. The file names should start with capital letter.
    3. Check log (control panel > stats > log browser) for errors.