how to call model class in controller

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

how to call model class in controller

samiuddin
This post has NOT been accepted by the mailing list yet.
Hi

All I am using the zend framework for the first time.

I tried the sample program from the book.

this is my 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';
require_once 'Zend/Loader/Autoloader.php';

$loader = Zend_Loader_Autoloader::getInstance();

$loader->registerNamespace('loudbite');

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


In one of my controller action i want to call the model class

but it is giving error

Warning: require_once(SaveAccount.php) [function.require-once]: failed to open stream: No such file or directory in C:\xampp\htdocs\loudbite\application\controllers\AccountController.php on line 25

please help me out.

Thanks and regards
Samiuddin
luk
Reply | Threaded
Open this post in threaded view
|

Re: how to call model class in controller

luk
This post has NOT been accepted by the mailing list yet.
samiuddin wrote
Hi

All I am using the zend framework for the first time.

I tried the sample program from the book.

this is my 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';
require_once 'Zend/Loader/Autoloader.php';

$loader = Zend_Loader_Autoloader::getInstance();

$loader->registerNamespace('loudbite');

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


In one of my controller action i want to call the model class

but it is giving error

Warning: require_once(SaveAccount.php) [function.require-once]: failed to open stream: No such file or directory in C:\xampp\htdocs\loudbite\application\controllers\AccountController.php on line 25

please help me out.

Thanks and regards
Samiuddin
You are reading Beginning Zend Framework by Armando Padilla. Your code does not work because your Controller does not see your Models classes. Try to modify your bit where you setup include_path and change it to this:

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

It will solve your issue.
Cheers, -- Luke Mierzwa