i have problem in zend framework basic application that class is not found. please help
i have basic structure and added model/tables directory. After my login page is displayed when i submit it then following error occurs
Fatal error: Class 'Application_models_tables_User' not found in E:\zendu\Apache2\htdocs\login\application\controllers\AuthController.php on line 18
Authcontroller.php
class AuthController extends Zend_Controller_Action
{
public function init()
{
/* Initialize action controller here */
}
public function indexAction()
{
// action body
}
public function loginAction()
{
$data = new Application_models_tables_User();
}
models/tables/User.php
class Application_models_tables_User extends Zend_Db_Table
{
protected $_name = 'users';
}
in application.ini
appnamespace = "Application"
i am using zend studio so basic structure is automaticaly created. so i have not to set include path of models.
Have a read through this :
The module resource autoloader sets the folder 'models' to the namespace Model.
I would change your class name to Application_Model_Table_User, and change your 'model/tables' folder to models/Table
Related
I am new to codeigniter hmvc . I have created a module folder called Hod under folder modules. In Hod module folder I have created controllers and views folders.In views folder i have two files called hod_welcome.php and pmo_welcome.php. Under controllers folder I have created two controller files called Hod.php and Pmo.php.
class Hod extends MY_Controller
{
public function __construct()
{
parent::__construct();
}
public function index()
{
$this->load->view('hod_welcome');
}
}
//this is pmo.php file code
class Pmo extends MY_Controller
{
public function __construct()
{
parent::__construct();
}
public function index()
{
$this->load->view('pmo_welcome');
}
}
http://localhost/ci_hmvc/hod - working
http://localhost/ci_hmvc/pmo - it is saying 404 - pagenot found
I am using Codeiniter 3.1.9
Where I am doing wrong? Any help would be greatly appreciated.
I want to have a login form when i click www.example.com/login with the help of action helper .
My controllers/helpers directory contain the file name
the class Login.php is
In my views/login/index.phtml i m calling it like this
<?= $this->loginForm; ?>
Login.php
<?
class Zend_Controller_Action_Helper_Login extends
Zend_Controller_Action_Helper_Abstract
{
function Login($a)
{
//Consists of form elements
}
}
?>
I get the following error ---------
"Helper "login" does not support overloading via direct()"
How to display the form and what is the error about ?
I was able to get it right this way .
http://geekabyte.blogspot.nl/2012/08/understanding-zend-frameworks-plugin.html
in the Bootstrap.php
public function _initLoader()
{
//For configuring Zend Application to be aware of the Controller Action Helper
Zend_Controller_Action_HelperBroker::addPath(APPLICATION_PATH .'/controllers/helpers');
}
The LoginController.php
class LoginController extends Zend_Controller_Action
{
public function init()
{
/* Initialize action controller here */
}
public function indexAction()
{
$this->_helper->login->scream();
}
}
In the controller/helpers/Login.php
class Zend_Controller_Action_Helper_Login extends Zend_Controller_Action_Helper_Abstract
{
Public function scream()
{
echo "Here please help!!!";
}
}
According to this blog post it should be possible to have an init() method within the model. Like this:
class MyModel
{
public function init()
{
// prepare something
}
...
}
This does not work for me. Does anybody know if I have to set somewhere a parameter (e.g. in the config file) or if this is not possible any more in my Zend FW version (1.11.4)? I checked with error_log('something') within the init method and it does not get called at all.
UPDATE:
I have extended Adam's solution a little:
public function __construct() {
if (get_parent_class($this) != false) {
parent::__construct();
}
if(method_exists($this, 'init')) {
$this->init();
}
}
This way it can be placed in a base class and then extended. Just in case someone needs the same solution later too.
That post is very misleading. If the model classes in the application extend Zend_Db_Table or Zend_Db_Table_Row, which is not the case in the post's examples but is implied from the text, then yes you can add an init() method that will be called automatically. For this to work in your application you would need to be calling the method from whatever creates your models, or from the constructor of a base class.
Try adding a call to init() from the constructor as so:
public function __construct()
{
parent::__construct();
$this->init();
}
you have that problem because a php class does not have an init method. That init method is only applicable to Zend classes. Which mean you can only use it when you extend a Zend class. Which means you are actually overriding the init method.
E.g. here it is in the Zend_Db_Table_Abstract class:
/**
* Initialize object
*
* Called from {#link __construct()} as final step of object instantiation.
*
* #return void
*/
public function init()
{
}
So if you change your model to extend zend it will work:
class MyModel extends Zend_Db_Table_Abstract
{
public function init()
{
// prepare something
}
...
}
It's the same with Zend_Controller_Action, which is why you can also use it in your controllers.
How to get resource in controller action?
Resource db was initialized in application.ini.
class IndexController extends Zend_Controller_Action
{
public function init()
{
/* Initialize action controller here */
}
public function indexAction()
{
// I want db resource here
}
}
Try and see if this works:
$this->getFrontController()->getParam('bootstrap')->getResource('db')
UPDATE : While this solution works, it is NOT a recommended
practice. Please, read comment by
#Brian M. below.
You can use Zend_Registry. Initialize the database connection in the bootstrap and store it in the registry:
// set up the database handler
// (...)
Zend_Registry::set('dbh', $dbh);
Then you can retireve it from anywhere else:
$dbh = Zend_Registry::get('dbh');
In answer to a similar question on Nabble, Matthew Weier O'Phinney (Mr Zend Framework 1) suggests using this form:
$this->getInvokeArg('bootstrap')->getResource('db');
So, in the context of this question, it would be something like:
class IndexController extends Zend_Controller_Action
{
public function init()
{
/* Initialize action controller here */
}
public function indexAction()
{
// db resource here
$db = $this->getInvokeArg('bootstrap')->getResource('db');
}
}
Yall:
I have a simple question, it might be a simple configuration issue, but
I have a Model defined, and when I try to access it from a controller it
fails.
The Model is in the model directory, and when I look at the quickstart app,
it seems like this should work.
Here is my model:
<?php
class Application_Model_User {
protected $_user;
protected $_password;
protected $_userId; // very simple right
}
?>
My controller just stops.. here is the controller code:
<?php
class UserController extends Zend_Controller_Action {
public function init() {
}
public function indexAction() {
// display login form
$users = new Application_Model_User();
echo "test never echos.. stopped above ? weird huh.."; // fails before ..
}
?>
Thank you everyone,
In application.ini
appnamespace = "Application_"
App structure:
/application/
/models/
/User.php
Class definition:
class Application_Model_User {}
Should work OK.