path issue in zendframework 2 - zend-framework

Currently I am transferring zend 2 from an server to another. I got some path issue. While I am accessing file with index.php it work for once and than stop working. like url - 11.11.11.11/index.php/user/login. in this case it worked fine for once and after set user name and password. It stop working.
What I have done is pointed server on pulic folder
.htaccess file
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} -s [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^.*$ - [NC,L]
RewriteRule ^.*$ index.php [NC,L]
</IfModule>
application.ini
includePaths.library = APPLICATION_PATH "/../library"
bootstrap.path = APPLICATION_PATH "/Bootstrap.php"
bootstrap.class = "Bootstrap"
appnamespace = "Application"
resources.frontController.controllerDirectory = APPLICATION_PATH "/controllers"
resources.frontController.params.displayExceptions = 1
resources.layout.layoutPath = APPLICATION_PATH "/layouts/scripts/"
resources.layout.layout = "default"
[staging : production]
phpSettings.display_startup_errors = 1
phpSettings.display_errors = 1
[testing : production]
phpSettings.display_startup_errors = 1
phpSettings.display_errors = 1
[development : production]
phpSettings.display_startup_errors = 1
phpSettings.display_errors = 1
resources.frontController.params.displayExceptions = 1
database.host = "localhost"
database.username = "xxx"
database.password = 'xxxxxx'
database.dbname = "xxx"
autoloadernamespaces[] = "Resources_"
autoloadernamespaces[] = "Plugins"
resources.frontController.plugins[] = "Plugins_ViewSetup"
index.php in public folder
defined('BASE_URL')
|| define('BASE_URL', 'http://11.11.11.11'); // Live
defined('APPLICATION_PATH')
|| define('APPLICATION_PATH', realpath(dirname(__FILE__) . '/../application'));
defined('CHARTS_FONT_PATH')
|| define('CHARTS_FONT_PATH', realpath(dirname(__FILE__) . '/../library/Charts/fonts'));
defined('PUBLIC_FOLDER')
|| define('PUBLIC_FOLDER', 'public');
defined('DATA_UPLOAD_PATH')
|| define('DATA_UPLOAD_PATH', realpath(dirname(__FILE__) . '/data'));
// 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';
/** Utilities */
require_once 'Utils.php';
// Create application, bootstrap, and run
$application = new Zend_Application(
APPLICATION_ENV,
APPLICATION_PATH . '/configs/application.ini'
);
$application->bootstrap()
->run();

I have solved this issue by enable Apache mod_rewrite

Related

Zend framework issue in tranfer from one server to another

I have transfer zend framework from one server to another.
its working fine but Auth controller is not working. it got error page not found issue, while a user login. Even it login the user but redirect on page not found. I am not sure where I need to make changes. Is it server issue or configuration issue as it work fine in my other server.
mod_rewrite of apache is enabled, server is pointed to public with .htaccess
.htaccess file
SetEnv APPLICATION_ENV development
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} -s [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^.*$ - [NC,L]
RewriteRule ^.*$ index.php [NC,L]
application.ini
includePaths.library = APPLICATION_PATH "/../library"
bootstrap.path = APPLICATION_PATH "/Bootstrap.php"
bootstrap.class = "Bootstrap"
appnamespace = "Application"
resources.frontController.controllerDirectory = APPLICATION_PATH "/controllers"
resources.frontController.params.displayExceptions = 1
resources.layout.layoutPath = APPLICATION_PATH "/layouts/scripts/"
resources.layout.layout = "default"
[staging : production]
phpSettings.display_startup_errors = 1
phpSettings.display_errors = 1
[testing : production]
phpSettings.display_startup_errors = 1
phpSettings.display_errors = 1
[development : production]
phpSettings.display_startup_errors = 1
phpSettings.display_errors = 1
resources.frontController.params.displayExceptions = 1
database.host = "localhost"
database.username = "xxx"
database.password = 'xxxxxx'
database.dbname = "xxx"
autoloadernamespaces[] = "Resources_"
autoloadernamespaces[] = "Plugins"
resources.frontController.plugins[] = "Plugins_ViewSetup"
index.php in public folder
defined('BASE_URL')
|| define('BASE_URL', 'http://11.11.11.11'); // Live
defined('APPLICATION_PATH')
|| define('APPLICATION_PATH', realpath(dirname(__FILE__) . '/../application'));
defined('CHARTS_FONT_PATH')
|| define('CHARTS_FONT_PATH', realpath(dirname(__FILE__) . '/../library/Charts/fonts'));
defined('PUBLIC_FOLDER')
|| define('PUBLIC_FOLDER', 'public');
defined('DATA_UPLOAD_PATH')
|| define('DATA_UPLOAD_PATH', realpath(dirname(__FILE__) . '/data'));
// 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';
/** Utilities */
require_once 'Utils.php';
// Create application, bootstrap, and run
$application = new Zend_Application(
APPLICATION_ENV,
APPLICATION_PATH . '/configs/application.ini'
);
$application->bootstrap()
->run();
There is some issue in database view access issue. I just debug code and check the error. Fixed

Zend Framework Error on _initAutoload() functon

I am learning Zend framework myself. I am facing error on initial installation of zend framework.
For start I created a controller for books BooksController.php
<?php
class BooksController extends Zend_Controller_Action
{
public function init()
{
/* Initialize action controller here */
}
public function indexAction()
{
/* Initialize action controller here */
}
public function listAction()
{
echo "hi";
$bookTBL = new Model_Books();
}
}
I created Books model on file Books.php
<?php
class Model_Books extends Zend_Db_Table_Abstract {
protected $_name = 'books';
}
To load Model_Books model I created _initAutoload() function at Bootstrap.php
<?php
class Bootstrap extends Zend_Application_Bootstrap_Bootstrap
{
protected function _initAutoload() {
$modelLoader = new Zend_Application_Module_Autoloader(array(
'namespace' => '',
'basePath' => APPLICATION_PATH
));
return $modelLoader;
}
}
I have also configured Database on application.ini
[production]
phpSettings.display_startup_errors = 1
phpSettings.display_errors = 1
includePaths.library = APPLICATION_PATH "/../library"
bootstrap.path = APPLICATION_PATH "/Bootstrap.php"
bootstrap.class = "Bootstrap"
appnamespace = "Application"
resources.frontController.controllerDirectory = APPLICATION_PATH "/controllers"
resources.frontController.params.displayExceptions = 0
database.adapter = mysql
database.params.host = localhost
database.params.username = root
database.params.password = 123456
database.params.dbname = zftutorial
[staging : production]
[testing : production]
phpSettings.display_startup_errors = 1
phpSettings.display_errors = 1
[development : production]
phpSettings.display_startup_errors = 1
phpSettings.display_errors = 1
resources.frontController.params.displayExceptions = 1
After these all coding when I tried to open http://localhost/zftutorial/public/books/list url in browser it is giving me Application error.
Please guide me where I have mistaken.
First of all make sure in which mode you are working if you dont know than simply specify it in your .htaccess like this:
Your file path: zftutorial/public/.htaccess
Add this line in it.
SetEnv APPLICATION_ENV development
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} -s [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^.*$ - [NC,L]
RewriteRule ^.*$ index.php [NC,L]
This will make sure that you are in development mode.
Remove this from your production mode for now:
database.adapter = mysql
database.params.host = localhost
database.params.username = root
database.params.password = 123456
database.params.dbname = zftutorial
and add this in your development mode:
[development : production]
resources.db.adapter = "PDO_MYSQL"
resources.db.params.host = "localhost"
resources.db.params.username = "root"
resources.db.params.password = "123456"
resources.db.params.dbname = "zftutorial"
This might solve your issue.

Cannot find application.php

hello am trying to install zend framework again after formating my machine but i keep getting this error...i have already done one project from previous installation but this time installation has just failed..
>>>Warning: require_once(Zend/Application.php) [function.require-once]: to open stream:
No such file or directory in C:\xampp\htdocs\home\public\index.php on line 18
Fatal error: require_once() [function.require]: Failed opening required 'Zend/Application.php' (include_path='C:\xampp\htdocs\home\library;“.') in C:\xampp \htdocs\home\public\index.php on line 18
This is my index.php page
>>// 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();
//
The application.php is already inside the library/zend package...
This is my application.ini
[production]
phpSettings.display_startup_errors = 0
phpSettings.display_errors = 0
includePaths.library = APPLICATION_PATH "/../library"
bootstrap.path = APPLICATION_PATH "/Bootstrap.php"
bootstrap.class = "Bootstrap"
appnamespace = "Application"
resources.frontController.controllerDirectory = APPLICATION_PATH "/controllers"
resources.frontController.params.displayExceptions = 0
[staging : production]
[testing : production]
phpSettings.display_startup_errors = 1
phpSettings.display_errors = 1
[development : production]
phpSettings.display_startup_errors = 1
phpSettings.display_errors = 1
resources.frontController.params.displayExceptions = 1
I just dont understand why it cant get that file yet it is inside the Zend folder...
Everything looks just fine from my perspective
Pliz help...thanks in advance
Make sure that your ZF library folder is in you include path in php.ini.
On my machine (typical windows + xampp), the file can be found in c:\xampp\php\php.ini
Look for the line:
include_path = "."
and change it to include you ZF library path
include_path = ".;C:\path\to\Zend\Parent\Directory";
If your ZF libraries are located in C:\xampp\ZF\library\Zend, the include path should be "C:\xampp\ZF\library".

Getting My ZF Application Seeing My Subdomain Routes

I'm working on a project that I'm using Zend_Hostname_Router_Route for.
My application is fairly simple. I have a a module named dev which I want to route to the dev subdomain. I have read a few articles on here and other sites to try to get a idea of what the problem is.
I am using ZF 1.12 for my application. I'm using the Zend_Hostname_Router_Route in my appllication.ini file as listed below:
[production]
phpSettings.display_errors = 0
includePaths.library = APPLICATION_PATH "/../library"
bootstrap.path = APPLICATION_PATH "/Bootstrap.php"
bootstrap.class = "Bootstrap"
appnamespace = "Application"
resources.frontController.controllerDirectory = APPLICATION_PATH "/controllers"
resources.frontController.moduleDirectory = APPLICATION_PATH "/modules"
resources.frontController.params.displayExceptions = 0
resources.layout.layoutPath = APPLICATION_PATH "/layouts/scripts/"
resources.view[] =
resources.view.encoding = "UTF-8"
resources.view.doctype = "HTML5"
resources.view.contentType = "text/html; charset=UTF-8"
phpSettings.display_startup_errors = 1
phpSettings.display_errors = 1
resources.db.adapter = "PDO_SQLITE"
resources.db.params.dbname = APPLICATION_PATH "/../data/db/guestbook.db"
[development:production]
phpSettings.display_startup_errors = 1
phpSettings.display_errors = 1
resources.frontController.params.displayExceptions = 1
resources.db.adapter = "PDO_SQLITE"
resources.db.params.dbname = APPLICATION_PATH "/..application/db/guestbook-dev.db"
resources.router.routes.type = "Zend_Controller_Router_Route_Hostname"
resources.router.routes.route = "dev.michaeldrowan.com"
resources.router.routes.chains.dev.type = "Zend_Controller_Router_Route"
resources.router.routes.chains.dev.route = ":controller/:action/"
resources.router.routes.chains.dev.defaults.module = "dev"
resources.router.routes.chains.dev.defaults.controller = "index"
resources.router.routes.chains.dev.defaults.action = "index"
The application in the ZF quickstart tutorial. So I shouldn't have problems setting this up. I have tried two index.php. On in public_html and one in subdomain in folder below(that is where my host puts it in). The index in the subdomain points to the dev module..I also tried the way of doing it that is how the zf quickstart tutorial
<?php
// Define path to application directory
defined('APPLICATION_PATH')
|| define('APPLICATION_PATH', realpath(dirname(__FILE__) . '/../michaeldrowan /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'
);
?>
and the index in the dev is:
<?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') : 'development'));
// 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();
?>
I have tried to point to the module in both by changing the 'production' to 'development'. I even tried 'development : production'
I've also tried to point the application to the module config and tried setting the application to the module too.
I'm running out of things to try. I hope someone can help me.
If you are using Apache write this in your .htaccess
RewriteCond %{HTTP_HOST} ^([a-zA-Z\-\.]+)\.yoursite\.com$ [NC]
RewriteRule ^(.*)$ index.php?someparam=%1 [QSA]
Then you can access subdomain name in your IndexController:
if ($this->getRequest()->getParam('someparam') == 'dev') {
// use routing
}

Problems integrating Zend Framework and Doctrine

I've done this before on another machine and the setup is almost identical. However, its just not working on the new machine. When I try and get Doctrine to generate my models, its putting them in the wrong place. Its creating an extra "Model" directory both for the base classes as well as the regular classes. I'm using Doctrine 1.2.3 with ZF 1.11.0. Here is my ZF application.ini:
[production]
phpSettings.display_startup_errors = 0
phpSettings.display_errors = 0
phpSettings.date.timezone = "America/Denver"
includePaths.library = APPLICATION_PATH "/../library"
bootstrap.path = APPLICATION_PATH "/Bootstrap.php"
bootstrap.class = "Bootstrap"
appnamespace = ""
resources.frontController.controllerDirectory = APPLICATION_PATH "/controllers"
resources.frontController.params.displayExceptions = 0
resources.layout.layoutPath = APPLICATION_PATH "/layouts/scripts"
resources.view[] =
autoloaderNamespaces[] = "Doctrine_"
autoloaderNamespaces[] = "App_"
doctrine.connection_string = "mysql://root#localhost/mydb"
;doctrine.cache = true
doctrine.data_fixtures_path = APPLICATION_PATH "/doctrine/data/fixtures"
doctrine.sql_path = APPLICATION_PATH "/doctrine/data/sql"
doctrine.migrations_path = APPLICATION_PATH "/doctrine/migrations"
doctrine.yaml_schema_path = APPLICATION_PATH "/doctrine/schema"
doctrine.models_path = APPLICATION_PATH "/models"
doctrine.generate_models_options.pearStyle = true
doctrine.generate_models_options.generateTableClasses = true
doctrine.generate_models_options.generateBaseClasses = true
doctrine.generate_models_options.baseClassPrefix = "Base_"
doctrine.generate_models_options.baseClassesDirectory =
doctrine.generate_models_options.classPrefixFiles = false
doctrine.generate_models_options.classPrefix = "Model_"
[staging : production]
[testing : production]
phpSettings.display_startup_errors = 1
phpSettings.display_errors = 1
[development : production]
phpSettings.display_startup_errors = 1
phpSettings.display_errors = 1
resources.frontController.params.displayExceptions = 1
Here is my Doctrine function from my ZF Bootstrap.php file:
protected function _initDoctrine()
{
$this->getApplication()->
getAutoloader()->
pushAutoloader(array('Doctrine_Core', 'autoload'));
$config = $this->getOption('doctrine');
$manager = Doctrine_Manager::getInstance();
$manager->setAttribute(Doctrine_Core::ATTR_MODEL_CLASS_PREFIX, 'Model_');
$manager->setAttribute(Doctrine_Core::ATTR_MODEL_LOADING, Doctrine_Core::MODEL_LOADING_PEAR);
$manager->setAttribute(Doctrine_Core::ATTR_VALIDATE, Doctrine_Core::VALIDATE_ALL);
$manager->setAttribute(Doctrine_Core::ATTR_USE_DQL_CALLBACKS, true);
$manager->setAttribute(Doctrine_Core::ATTR_AUTO_FREE_QUERY_OBJECTS, true);
$manager->setAttribute(Doctrine_Core::ATTR_AUTO_ACCESSOR_OVERRIDE, true);
$manager->setAttribute(Doctrine_Core::ATTR_AUTOLOAD_TABLE_CLASSES, true);
if (isset($config['cache']) && $config['cache'] == true) {
$cacheDriver = new Doctrine_Cache_Apc();
$manager->setAttribute(Doctrine_Core::ATTR_QUERY_CACHE, $cacheDriver);
}
$connection = $manager->openConnection($config['connection_string'], 'doctrine');
$connection->setAttribute(Doctrine_Core::ATTR_USE_NATIVE_ENUM, true);
$connection->setCharset('utf8');
return $connection;
}
And here is my doctrine.php command line script:
// 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->getBootstrap()->bootstrap('doctrine');
$config = $application->getOption('doctrine');
$cli = new Doctrine_Cli($config);
$cli->run($_SERVER['argv']);
So, I'm expecting my models directory to end up like this:
models
Base
-Class1.php
-Class2.php
-Class1.php
-Class1Table.php
-Class2.php
-Class2Table.php
where the base class class names are formatted like Model_Base_Class1 and the regular class names are Model_Class1 (in the actual php files themselves). Instead, what I'm getting is:
models
Base
Model
-Class1.php
-Class2.php Model
-Class1.php
-Class1Table.php
See the extra Model directories? What is causing this? I've tried messing with the doctrine.generate_models_options.classPrefix option in my ini as well as the similar setting in my Bootstrap.php file - $manager->setAttribute(Doctrine_Core::ATTR_MODEL_CLASS_PREFIX, 'Model_');
Please help me!
Well, I'm not so smart once again. :( All it was, was a misconfiguration of my schema.yaml file. I had put Model_User as the model name instead of just User! The fixtures file does require it to be Model_User though. Problem solved.