Jump to content

Recommended Posts

here's the screenshot of the error

vxj6uf.jpg

 

here's the indexController code


<?php

class IndexController extends Zend_Controller_Action
{

    public function init()
    {
        /* Initialize action controller here */
    }

    public function indexAction()
    {
        $this->view->title = "My Albums";
        $this->view->headTitle($this->view->title);
        
        $albums = new Application_Model_DbTable_Albums();
        $this->view->albums = $albums->fetchAll();
    }

    public function addAction()
    {
        // action body
    }

    public function editAction()
    {
        // action body
    }

    public function deleteAction()
    {
        // action body
    }


}

 

here's the albums.php model class (the alleged missing class ? )

<?php 

class Application_Model_DbTable_Albums extends Zend_Db_Table_Abstract
{
protected $_name = 'albums';

public function getAlbum($id)
{
	$id = (int)$id;
	$row = $this->fetchRow('id = '. $id);
	if(!$row)
	{
		throw new Exception("Could not find row $id");
	}
	return $row->toArray();
}

public function addAlbum($artist,$title)
{
	$data = array(
			'artist'=>$artist,
			'title'=>$title
	);
	$this->insert($data);
}

public function updateAlbum($id,$artist,$title)
{
	$data = array(
			'artist'=>$artist,
			'title'=>$title
	);
	$this->update($data,'id = '.(int)$id);
}

public function deleteCd($id)
{
	$this->delete('id = '.(int)$id);
}
}

?>

 

here's the view of index.phtml

 

<p><a href="<?php echo $this->url(array('controller'=>'index','action'=>'add'));?>">
Add new album</a></p>
<table>
<tr>
<th>Title</th>
<th>Artist</th>
<th> </th>
</tr>
<?php foreach($this->albums as $album): ?>
<tr>
<td><?php echo $this->escape($album->title);?></td>
<td><?php echo $this->escape($album->artist);?></td>
<td>
	<a href="<?php echo $this->url(array(
										'controller'=>'index',
										'action'=>'edit',
										'id'=>$cd->id));?>">Edit</a>
	<a href="<?php echo $this->url(array(
										'controller'=>'index',
										'action'=>'delete',
										'id'=>$album->id));?>">Delete</a>
</td>
</tr>
<?php endforeach;?>
</table>

 

and here's the screenshot of the folder structures

2h50c3n.jpg

 

I don't know why the hell it's giving me that error, am just following the akrabat's tutorial on zend framework 1.10

Link to comment
https://forums.phpfreaks.com/topic/204824-class-missing-please-help/
Share on other sites

this is what i have in the public/index.php file

<?php

// Define path to application directory
defined('APPLICATION_PATH')
    || define('APPLICATION_PATH', realpath(dirname(__FILE__) . '/../application'));

// Define application environment
defined('APPLICATION_ENV')
    || define('APPLICATION_ENV', (getenv('APPLICATION_ENV') ? getenv('APPLICATION_ENV') : 'production'));

// Ensure library/ is on include_path
set_include_path(implode(PATH_SEPARATOR, array(
    realpath(APPLICATION_PATH . '/../library'),
    get_include_path(),
)));

/** Zend_Application */
require_once 'Zend/Application.php';

// Create application, bootstrap, and run
$application = new Zend_Application(
    APPLICATION_ENV,
    APPLICATION_PATH . '/configs/application.ini'
);
$application->bootstrap()
            ->run();

 

is that where the application/models should exists ? or you're referring to a different thing ?

Its been a long while since I've used Zend and there could be a more standard way of doing it but, if you want your Models directory on your path you need to add it.

 

set_include_path(implode(PATH_SEPARATOR, array(
    realpath(APPLICATION_PATH . '/../library'),
    realpath(APPLICATION_PATH . '/Model'),
    get_include_path(),
)));

 

Also, your models directory should be named Model and the albums.php file should be named Albums.php

Register the namespace Application_ and it's path with the Loader, you can do this within your configuration file.

 

http://framework.zend.com/manual/en/zend.application.core-functionality.html

 

autoloaderNamespaces.Application_ = "library/Application/"

You should look up resource autoloaders.  You'll need to register Application as a resource namespace like so:

$resourceLoader = new Zend_Loader_Autoloader_Resource(array(
    'basePath'  => 'path/to/application',
    'namespace' => 'Application',
));

The code should go into your bootstrap class (assuming you're using Zend_Application).

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

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