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.
Related
I am creating custom plugin in zend framework using Zend_Controller_Plugin_Abstract in the disptach method i am using the following code
public function preDispatch(Zend_Controller_Request_Abstract $request)
{
global $serversetting;
$serversetting = 'S3Server';
}
Now I want to use the value of $serversetting inside my controller
How Can i use them??
Thanks In Advance !!
class MyclassController extends Zend_Controller_Action
{
private $_serversetting;
public function preDispatch(Zend_Controller_Request_Abstract $request) {
$this->_serversetting = 'S3Server'; //set
}
[...]
public function otherAction() {
[...]
$foo = $this->_serversetting; //get
[...]
}
}
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
In this example I want increase the session variable called "test" by one each time it enter to the controller. If comment the content of the method preDispath works fine but with this precise example, the session variable "test" increase in 3 or 5 each time.
I use Zend Framework 1.11.4
Why??? I hope you understand my question.
Remember this example is only to show the strange behavior of the method preDispatch
My plugin
class App_Plugins_Permisos extends Zend_Controller_Plugin_Abstract{
public function __construct(){}
public function preDispatch(Zend_Controller_Request_Abstract $request) {
$request->setModuleName('default');
$request->setControllerName('index');
$request->setActionName('index');
}
}
My bootstrap
class Bootstrap extends Zend_Application_Bootstrap_Bootstrap{
protected function _initSession(){
Zend_Session::start();
}
protected function _initPlugins(){
$this->bootstrap('frontcontroller');
$this->frontController->registerPlugin(new App_Plugins_Permisos());
}
}
My Controller
class IndexController extends Zend_Controller_Action{
public function init(){}
public function indexAction(){
$s = new Zend_Session_Namespace('test');
if(isset($s->test)){
$s->test++;
}else{
$s->test = 1;
}
Zend_Debug::Dump($s->test);
die();
}
}
Thanks a lot
Try it putting in .ini resources.frontController.plugins.foo = "My_Plugin_Foo"
If works tell me! Tnks
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.