Yii2 change default Route to another namespace - php

the default route in Yii2 is #app/controllers/SiteController.
but If I build from beginning.
composer require yiisoft/yii2
then I create my own index.php and set the configure for the app
(new yii\web\Application($config))->run();
and the application is always try to local the defaultContoller in the app namespace. but If i put the SiteController in another namespace. it gives me 404 error,
index.php
require(__DIR__ . '/vendor/autoload.php');
require(__DIR__ . '/vendor/yiisoft/yii2/Yii.php');
$config = require(__DIR__ . '/repo/config/web.php');
(new yii\web\Application($config))->run();
web.php
'id' => 'repo',
'basePath' => dirname(__DIR__),
'controllerNamespace' => 'repo\\controllers',
'defaultRoute' => 'site/index',
folder structure
/vendor
-yiisoft
/repo
-config
---web.php
-controllers
---SiteController.php
SiteController.php
<?php
namespace repo\controllers;
use Yii;
use yii\web\Controller;
class SiteController extends Controller{
public function actionIndex(){
echo 'welcome to the site';
}
}
?>
if I give the SiteController.php namespace app/controllers it works,but once I change it back to repo/controllers it says page not found.

try this in you config file:
'controllerNamespace' => 'newnamespace\controllers',
'defaultRoute' => 'new/index',

yii\base\Application object has a public property controllerNamespace, which defaults to app\\controllers, you need to change it accordingly to changing default controller namespace.
Add this to your application config:
[
...
'controllerNamespace' => 'app\\other\\namespace\controllers',
...
],
Default route is site (for yii\web\Application), it can be changed the same way (defaultRoute property):
[
...
'defaultRoute' => 'otherDefaultRoute',
...
],

I found I forgot to define the root alias.
// $className is a fully qualified class name without the leading backslash
$classFile = Yii::getAlias('#' . str_replace('\\', '/', $className) . '.php');
so If I define the root alias #repo in the configuration. then it works
'aliases' => [
'#repo' => dirname(__DIR__),
],

Related

CakePHP4: Where should I put my custom PasswordHasher

I implemented CakePHP4 authentication following this:
https://book.cakephp.org/4/en/tutorials-and-examples/cms/authentication.html
It worked, then I need to use my custom PasswordHasher to satisfy the client requirements. I couldn't find any tutorial to do that, but figured out the following code works.
In Application.php:
public function getAuthenticationService(ServerRequestInterface $request): AuthenticationServiceInterface {
// ....
$authenticationService->loadIdentifier('Authentication.Password', [
'fields' => [
'username' => 'username',
'password' => 'password',
],
'passwordHasher' => [
'className' => 'Authentication.MyCustom',
]
]);
The problem is that I need to put MyCustomPasswordHasher.php file in vendor\cakephp\authentication\src\PasswordHasher in order to make this work. Of course I don't want to put my own code under vendor directory.
Temporarily, I created and used src\Authentication\PasswordHasher directory and forced to make it work by doing this:
spl_autoload_register(function ($class) {
if (strpos($class, 'MyCustomPasswordHasher') !== false) {
require_once __DIR__ . '/' . str_replace(['\\', 'App/'], [DS, ''], $class) . '.php';
}
});
Is there any cleaner way to accomplish the purpose in CakePHP4? Where should I put custom codes?
Don't use plugin notation for the short name, pass only 'MyCustom', then it will look inside of your application, in the App\PasswordHasher namespace, so your class would accordingly go into
src/PasswordHasher/MyCustomPasswordHasher.php
Alternatively you can always pass a fully qualified name, meaning you could put your class wherever you want, as long as the composer autoloader can resolve it:
'passwordHasher' => [
'className' => \Some\Custom\Namespaced\PasswordHasher::class,
]

Loading Modules which has multiple module in Zend Framework 2

Issues
So I try to decouple my application to multiple module project ( each has its own composer.json ), then the real application will load all this project through composer
Each of this module project will have a user-interface accessible through browser and can start individually, so it's not just a simple library. This file will exist on each module project:
config/application.config.php
public/index.php
Example Module ( Dependency is what I write in module array in application.config.php ):
UIModule
Dependency : AssetManager, UIModule
CMSModule
Dependency : UIModule, CMSModule
AccountingModule:
Dependency : UIModule, AccountingModule
Now in my final application lets say MyApplication it need both CMSModule and AccountingModule, but I cannot write only just this two module in application.config.php. Instead I have to write:
AssetManager -> this should be load by UIModule
UIModule -> this should be load by CMS/Accounting Module
CMSModule
AccountingModule
I should only require to write this two in MyApplication
CMSModule
AccountingModule
Is this can be done ? which I think what this guy want to achieve in Loading Modules Dynamically in Zend Framework 2
Something like this, I add another additional module.
Based on our exchange in the comments and the question, you're going to need at least 3 applications. I'll give you a quick examples, you'll have to update your requirements for each application yourself. After the composer.json configs I'll give you a skeleton module to use as a theme module.
These config's are to be used as the root composer.json config files. Each of the required packages should have their own composer file listing requirements for the specific package.
For example, a "core" module would require various Zend Framework packages. A "theme" package could be requiring other ZF packages, such as zendframework/zend-view in order to be able to have a GUI layout.
Setting up 3 separate Zend Framework applications with overlapping requirements
composer.json for application 1
{
"name": "COMPANY_NAME/APPLICATION_1",
"require": {
"COMPANY_NAME/MODULE_1_THEME": "*",
"COMPANY_NAME/MODULE_2_CMS": "*"
},
"repositories": [
{
"type": "git",
"url": "git#github.com/COMPANY_NAME/MODULE_1_THEME.git"
},
{
"type": "git",
"url": "git#github.com/COMPANY_NAME/MODULE_2_CMS.git"
},
]
}
composer.json for application 2
{
"name": "COMPANY_NAME/APPLICATION_2",
"require": {
"COMPANY_NAME/MODULE_1_THEME": "*",
"COMPANY_NAME/MODULE_3_ACCOUNTING": "*"
},
"repositories": [
{
"type": "git",
"url": "git#github.com/COMPANY_NAME/MODULE_1_THEME.git"
},
{
"type": "git",
"url": "git#github.com/COMPANY_NAME/MODULE_3_ACCOUNTING.git"
},
]
}
composer.json for application 3 (has no theme)
{
"name": "COMPANY_NAME/APPLICATION_3",
"require": {
"COMPANY_NAME/MODULE_4_AUTH_MODULE": "*"
},
"repositories": [
{
"type": "git",
"url": "git#github.com/COMPANY_NAME/MODULE_4_AUTH_MODULE.git"
}
]
}
As you can see, the Applications 1 & 2 use the same MODULE_THEME package, as you outlined in the diagram in your question.
Now, the creation of a package for Zend Framework is pretty much the same for every package you create, so modify what follows to the requirements you have for each module (in a package).
Creating a theme module
This module basically replaces the Application module that you get by default when you install the Zend Framework (2 or 3) Skeleton Application.
I've recently upgraded everything I have with Zend Framework to Zend Framework 3, so I'll be giving you a setup tailored for ZF3. However, downgrading for ZF2 should not be too much of an issue.
Create config for what you need
A typical theme needs a few things, such as:
themes/layouts for different types of pages (e.g. login, normal theme, errors)
translations
showing errors (when in dev mode)
default "home" route
controller to handle default "home" route
Config for this could be (not limited to! Do with it what you wish!) as such in the module.config.php of the Theme module
namespace COMPANY_NAME\Theme;
use COMPANY_NAME\Theme\Controller\ThemeController;
use COMPANY_NAME\Theme\Factory\ThemeControllerFactory;
return [
'controllers' => [
'factories' => [
ThemeController::class => ThemeControllerFactory::class,
],
],
'router' => [
'routes' => [
'home' => [
'type' => Literal::class,
'may_terminate' => true,
'options' => [
'route' => '/',
'defaults' => [
'controller' => ThemeController::class,
'action' => 'index',
],
],
],
],
],
'route_layouts' => [
'*' => 'layout/layout',
'login' => 'layout/login',
'register' => 'layout/login',
'error*' => 'error/index',
'error/404' => 'error/404',
],
'translator' => [
'locale' => 'en_US',
'translation_file_patterns' => [
[
'type' => 'gettext',
'base_dir' => __DIR__ . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . 'language',
'pattern' => '%s.mo',
],
],
],
'view_manager' => [
// controller_map is optional, but depending on your composer package nesting, could be a great help. Have a look here for how to use: https://blog.alejandrocelaya.com/2015/08/14/working-with-sub-namespaced-modules-in-zend-framework-2-the-right-way/
'controller_map' => [
'COMPANY_NAME\Theme' => 'company_name_path_alias',
],
'display_not_found_reason' => true,
'display_exceptions' => true,
'doctype' => 'HTML5',
'not_found_template' => 'error/404',
'exception_template' => 'error/index',
'template_map' => [
'layout/layout' => __DIR__ . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . 'view' . DIRECTORY_SEPARATOR .
'layout' . DIRECTORY_SEPARATOR . 'layout.phtml',
'layout/login' => __DIR__ . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . 'view' . DIRECTORY_SEPARATOR .
'layout' . DIRECTORY_SEPARATOR . 'login.phtml',
'error/404' => __DIR__ . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . 'view' . DIRECTORY_SEPARATOR .
'error' . DIRECTORY_SEPARATOR . '404.phtml',
'error/index' => __DIR__ . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . 'view' . DIRECTORY_SEPARATOR .
'error' . DIRECTORY_SEPARATOR . 'index.phtml',
],
'template_path_stack' => [
__DIR__ . DIRECTORY_SEPARATOR .'..' . DIRECTORY_SEPARATOR . 'view',
],
],
];
File/module structure based on config
The location of the package would be /vendor/COMPANY_NAME/THEME_MODULE_NAME (as you would've defined in the name property in the composer.json file for this package.
The folder/file structure would be:
/vendor/COMPANY_NAME/THEME_MODULE_NAME
config/
module.config.php
src/
Controller/
ThemeController.php
Factory/
ThemeControllerFactory.php
Module.php
view/
error/
index.phtml
404.phtml
layout/
index.phtml
login.phtml
register.phtml
composer.json
ThemeController & *Factory
These are very simple as the Controller is pretty much a clone of the original IndexController provided by the Skeleton Application. The Factory in this instance does nothing but return the Controller. As such you could replace the config for it with the FQCN to the InvokableFactory of Zend Framework 3 and not make the Factory class. However, if your ThemeController needs some requirements (such as a RegisterForm), you're going to need the Factory to provide these.
ThemeController
namespace COMPANY_NAME\Controller;
use Zend\Mvc\Controller\AbstractActionController;
class ThemeController extends AbstractActionController
{
public function indexAction()
{
return [];
}
}
ThemeControllerFactory
namespace COMPANY_NAME\Factory;
use COMPANY_NAME\Controller\ThemeController;
use Zend\ServiceManager\Factory\FactoryInterface;
class ThemeControllerFactory implements FactoryInterface
{
/**
* #param ContainerInterface $container
* #param string $requestedName
* #param array|null $options
* #return ThemeController
* #throws \Psr\Container\ContainerExceptionInterface
* #throws \Psr\Container\NotFoundExceptionInterface
*/
public function __invoke(ContainerInterface $container, $requestedName, array $options = null)
{
return new ThemeController();
}
}
Theme composer requirements
Obviously your modules will not have the same requirements. Make sure you figure out what they are, per module.
For my own Theme module, I have the following Zend Framework requirements in my composer.json file:
{
"name": "COMPANY_NAME/THEME_MODULE_NAME",
"require": {
"zendframework/zend-di": "*",
"zendframework/zend-navigation": "*",
"zendframework/zend-view": "*",
}
}
In the require section I also have: "rwoverdijk/assetmanager": "^1.6",. This module is used to mash together all CSS, JS (any type really) of file to a determined location. I would advise you to have a look at it (here).
Notes on the answer
Replace COMPANY_NAME with the username of your Github account (or the identifying account name if your using Bitbucket or Gitlab)
Replace THEME_MODULE_NAME with the name of the repository
If/when possible, use explicit versions for required packages (e.g. "rwoverdijk/assetmanager": "^1.6"). Version locking can save you a lot of hassle in the future...
Additionally: using a package as a "Theme module" allows you to completely remove the module/ folder originally shipped with the Skeleton Application of Zend Framework. However, you're hereby advised to use the module/ folder for application specific modules. If you create a package for everything, you'll soon find yourself maintenance hell.
Yep your layout is what I came at the end
However, you're hereby advised to use the module/ folder for application specific modules.
Kind of, I end up putting inside a folder for every specific package ( zf2 style )
PACKAGE FOLDER
composer.json
Module.php (this for php unit test)
public (for UI Package I have this)
index.php
config
application.config.php (apparently need to write each version for each package)
tests
src
MODULE_NAME
asset
src
MODULE_NAME
Controller
Service
Model
{ Other ... }
config
view
Module.php
Thanks for your clarification and answer.

Cant resolve site/index after splitting in two "modules"

I wanted to split manager and frontend:
root/manager/controllers/SiteController.php
namespace manager\controllers;
use Yii;
use yii\filters\AccessControl;
use yii\web\Controller;
use yii\filters\VerbFilter;
use app\models\LoginForm;
use app\models\ContactForm;
class SiteController extends Controller
{
public function actionIndex()
{
echo 'hallo';
//return $this->render('index');
}
}
root/manager/config/web.php
$params = require(__DIR__ . '/params.php');
$config = [
'id' => 'basic',
'basePath' => dirname(__DIR__),
'controllerNamespace' => 'manager\controllers',
'bootstrap' => ['log'],
'modules' => [
'manager' => [
'class' => 'manager\Module',
],
],
'components' => [
'request' => [
// !!! insert a secret key in the following (if it is empty) - this is required by cookie validation
'cookieValidationKey' => 'X',
],
'cache' => [
'class' => 'yii\caching\FileCache',
],
'user' => [
'identityClass' => 'app\models\User',
'enableAutoLogin' => true,
],
'errorHandler' => [
'errorAction' => 'site/error',
],
'mailer' => [
'class' => 'yii\swiftmailer\Mailer',
// send all mails to a file by default. You have to set
// 'useFileTransport' to false and configure a transport
// for the mailer to send real emails.
],
'log' => [
'traceLevel' => YII_DEBUG ? 3 : 0,
'targets' => [
[
'class' => 'yii\log\FileTarget',
'levels' => ['error', 'warning'],
],
],
],
'db' => require(__DIR__ . '/db.php'),
'urlManager' => [
'enablePrettyUrl' => true,
'showScriptName' => false,
'rules' => [
'' => 'site/index',
'fragebogen/erstellung/<id>' => 'questionary/creation',
'fragebogen/erstellung' => 'questionary/creation',
'auftraege-importieren' => 'upload/jobs',
'auftraege-erfolgreich-importiert' => 'upload/jobssuccess',
],
],
],
'params' => $params,
];
if (YII_ENV_DEV) {
// configuration adjustments for 'dev' environment
$config['bootstrap'][] = 'debug';
$config['modules']['debug'] = 'yii\debug\Module';
$config['bootstrap'][] = 'gii';
$config['modules']['gii'] = 'yii\gii\Module';
}
return $config;
root/manager/web/index.php
<?php
// comment out the following two lines when deployed to production
defined('YII_DEBUG') or define('YII_DEBUG', true);
defined('YII_ENV') or define('YII_ENV', 'dev');
require(__DIR__ . '/../../vendor/autoload.php');
require(__DIR__ . '/../../vendor/yiisoft/yii2/Yii.php');
$config = require(__DIR__ . '/../config/web.php');
(new yii\web\Application($config))->run();
And i get this error:
exception 'yii\base\InvalidRouteException' with message 'Unable to resolve the request "site/error".' in /kunden/xxx/xxx/vendor/yiisoft/yii2/base/Module.php:461 Stack trace:
#0 /kunden/xxx/xxx/vendor/yiisoft/yii2/web/ErrorHandler.php(80): yii\base\Module->runAction('site/error')
#1 /kunden/xxx/xxx/vendor/yiisoft/yii2/base/ErrorHandler.php(95): yii\web\ErrorHandler->renderException(Object(yii\web\NotFoundHttpException))
#2 [internal function]: yii\base\ErrorHandler->handleException(Object(yii\web\NotFoundHttpException))
#3 {main} Previous exception: exception 'yii\base\InvalidRouteException' with message 'Unable to resolve the request "site/index".' in /kunden/xxx/xxx/vendor/yiisoft/yii2/base/Module.php:461 Stack trace:
#0 /kunden/xxx/xxx/vendor/yiisoft/yii2/web/Application.php(83): yii\base\Module->runAction('site/index', Array)
#1 /kunden/xxx/xxx/vendor/yiisoft/yii2/base/Application.php(375): yii\web\Application->handleRequest(Object(yii\web\Request))
#2 /kunden/xxx/xxx/manager/web/index.php(12): yii\base\Application->run()
#3 {main}
Next exception 'yii\web\NotFoundHttpException' with message 'Unable to resolve the request "site/index".' in /kunden/xxx/xxx/vendor/yiisoft/yii2/web/Application.php:95 Stack trace:
#0 /kunden/xxx/xxx/vendor/yiisoft/yii2/base/Application.php(375): yii\web\Application->handleRequest(Object(yii\web\Request))
#1 /kunden/xxx/xxx/manager/web/index.php(12): yii\base\Application->run()
#2 {main}
is this topic resolved?
If not, check your bootstrap file in common/config/bootstrap.php.
If your application is trying to use a path alias and it can't be resolved you will get the following exception!
exception 'yii\base\InvalidRouteException' with message 'Unable to resolve the request "site/error".
Example
wrong path is
Yii::setAlias('backend', dirname(dirname(DIR)) . 'backend');
correct path is
Yii::setAlias('backend', dirname(dirname(DIR)) . '/backend');
I think controllerNamespace may be deprectated in Yii2?
Can you replace that in your config, and use a controllerMap?
'controllerMap' => [
'site' => 'manager\controllers\SiteController',
],
Try removing the url rules, you might have to define the default rule to include the module name of at least. See this Custom URL rules with modules in Yii2
EDIT
Take a look at my installations instructions for my module https://github.com/Mihai-P/yii2-core
In short, not sure what controllerNamespace does there, you should remove it. I do something similar here: https://github.com/Mihai-P/yii2-core/blob/master/Module.php
Afterwards this
'class' => 'manager\Module'
I do not think that will work, where is the manager namespace? How would Yii know to look for it? I use composer to add the namespace in the autoloader, you should probably do something like that manually. Tell Yii that manager means your manager folder, afterwards it will find the controllers.
Also this might help, creating an alias to that folder https://github.com/Mihai-P/yii2-core#note-2
There are some config settings which look questionable to me, first
'modules' => [
'manager' => [
'class' => 'manager\Module',
],
],
Since you've created a separate app, you should remove this setting. From your screenshot there
are also no modules in the manager application.
For debugging, just set enablePrettyUrl URL to false and reeable it after it is working without
nice URLs.
You may also need set an alias in bootstrap.php for manager, not sure about that, but worth a try.
From your error message I'd say that the application is not able to load the SiteController at all,
because site/error fails also.
Addon: Personally, I'd recommend just one app per project, but I know that this a controversial topic.
It just looked to me, like you had that and were switching to two apps for some reason. If you just want to
apply a custom theme to your manager, you could easily do that by module configuration
...
I guess you dont have an alias to your application folder. Maybe autoloading component cannot find your controller file. You can add an alias in your config file doing:
\Yii::setAlias(’#manager’, dirname(__FILE__).'/..');
But I think the best way is to create another module for manager instead of dividing into different namespaces.
I have observed that this error generally occurs due to mis-configuration or due to case sensitive names of classes and namespaces. In my case the error was due to the configuration of ii8n component. I was using the following configuration
'i18n' => [
'translations' => [
'*' => [
'class' => 'yii\i18n\PhpMessageSource',
'basePath' => '#backend/messages',
'sourceLanguage' => 'en-US',
'forceTranslation'=> true,
],
],
],
The issue was resolved after I removed the configuration
I guess you dont have an alias to manager folder.
add an alias in your common\config\bootstrap.php.
Yii::setAlias('#manager', dirname(dirname(__DIR__)) . '/manager');
so your common\config\bootstrap.php file should look like:
Yii::setAlias('#common', dirname(__DIR__));
Yii::setAlias('#frontend', dirname(dirname(__DIR__)) . '/frontend');
Yii::setAlias('#backend', dirname(dirname(__DIR__)) . '/backend');
Yii::setAlias('#console', dirname(dirname(__DIR__)) . '/console');
Yii::setAlias('#manager', dirname(dirname(__DIR__)) . '/manager');

Phalcon Incubator not loading translation namespace

I have have added the composer require:
{
"require": {
"phalcon/incubator": "dev-master"
}
}
I've added the location to the Phalcon loader file (is this correct?):
$loader = new \Phalcon\Loader();
/**
* We're a registering a set of directories taken from the configuration file
*/
$loader->registerNamespaces(array(
'Phalcon' => __DIR__ . '/../../vendor/phalcon/incubator/Library/Phalcon/',
'APPNAME\Models' => $config->application->modelsDir,
'APPNAME\Controllers' => $config->application->controllersDir,
'APPNAME\Forms' => $config->application->formsDir,
'APPNAME' => $config->application->libraryDir
));
$loader->register();
Then I have this in my controller:
$translate = new Phalcon\Translate\Adapter\Gettext(array(
'locale' => 'en_GB',
'file' => 'messages',
'directory' => '../app/lang'
));
But I get the following error:
Why isn't it loading the Incubator files?
Thanks
Nathan
You need to use FQCN when you are not including namespaces using the use keyword: (not the first \ in the FQCN)
$translate = new \Phalcon\Translate\Adapter\Gettext(array(
'locale' => 'en_GB',
'file' => 'messages',
'directory' => '../app/lang'
));
If you don't do this, the namespace is assumed to be relative to the current namespace (which is defined by the namespace statement at the top of the file)
Btw, you don't need to configure the Phalcon autoloading, composer takes care of the autoloading of Phalcon for you. I would also recommend using Composer's autoloader instead of both Composer's and phalcon's loaders.

Zend Framework 11.1: Form_Customer not found in

First of all, I know there are a few quite similar questions here on stackoverflow about that form problem but none of them could actually help me so I'm giving it a try myself. I've been stuck with this for the past 10 hours and I'm really desesperate right now.
So, let's start with my directory structure:
gpos/
---- application/
--- forms/
------- CustomerForm.php
--- modules/
--- default/
--- controllers/
--- CustomerController.php
--- views/
--- Bootstrap.php
---- public/
---- library/
--- Doctrine/
--- GPos/
--- Doctrine/
--- ActiveEntity.php
--- Models/
--- Customer.php
As you can see, I'm using Zend's standard forms/ folder to store my forms and I'm also using Doctrine as DB manager.
So I've been trying to reach my CustomerForm.php from CustomerController.php but simply getting a not found error.
Here is the error I'm getting:
Fatal error: Class 'Form_CustomerForm' not found in C:\wamp\www\GPos\gpos\application\modules\default\controllers\CustomerController.php on line 9
CustomerController.php:
class CustomerController extends Zend_Controller_Action {
public function init() {
/* Initialize action controller here */
}
public function indexAction() {
$form = new Form_CustomerForm(); //line 9
$form->setAction('/customer/index');
$form->setMethod('post');
$this->view->form = $form;
}
and CustomerForm.php:
class Form_CustomerForm extends Zend_Form {
public function init() {
and finally views/scripts/customer/submit.phtml:
<h2>Customer</h2>
<p>To create blabla</p>
<?php echo $this->form; ?>
I've been desesperately trying to add Form namespace to the autoloader but I learned today that it was already in thanks to Zend doing it for us. So... What am I doing wrong? I found tons of posts saying how to add resources and how to manage custom forms and I feel I'm doing exactly what's asked but it just won't work not matter what.
I'm afraid that it comes from somewhere else cause I've been trying to add different namespaces unsuccessfully too such as GPos_Doctrine for my ActiveEntity.php file in library/GPos/Doctrine/ with:
protected function _initAutoload()
{
$autoloader = new Zend_Application_Module_Autoloader(array(
'namespace' => 'Application',
'basePath' => APPLICATION_PATH,
));
$autoloader->addResourceType('gpos', '/../../library/GPos', 'GPos');
$autoloader->addResourceType('doctrine', '/../../library/GPos/Doctrine', 'GPos_Doctrine');
return $autoloader;
}
This didn't work either. I'm quite unsure of the 'path' parameter (2nd param) but I saw in a tutorial that the path of eath resource type you add must be relative to autoloader's basePath, so I came up with these paths.
The only way I could make my GPos_Doctrine_ActiveEntity() work was by adding autoloadernamespaces[] = "GPos_" to application.ini. Adding autoloadernamespaces[] = "Form_"didn't work though... I really don't understand what's wrong with my resource types I'm adding.
Please note that I didn't use zf tools to build that project. I'm considering doing it if I don't find a way to make it all work correctly.
I've also tried to rename my form class to "Application_Form_CustomerForm" but didn't do any good either. I feel I've tried everything I could now. I'm just deseperate :(
Oh and by the way, the only work around I found at first is to put forms/ folder in my library, that worked. Don't understand why, but I don't want to use that hack. See, I'm doing this project as my IT Bachelor work graduation and I really shouldn't get into hacking things to make them work :P.
Thank you for anybody paying attention!
either add an bootstrap to the default module (which in turn sets the resourcetypes automaticly)
class Default_Bootstrap extends Zend_Application_Module_Bootstrap
{
protected function _initAutoload() {
$moduleLoader = new Zend_Application_Module_Autoloader(array(
'namespace' => 'Default_',
'basePath' => APPLICATION_PATH . '/modules/default'));
return $moduleLoader;
}
}
or add this to your global bootstrap (extend it with your two custom resourcetypes):
public function _initDefaultResourceTypes() {
$al = new Zend_Application_Module_Autoloader(array(
'namespace' => '',
'basePath' => APPLICATION_PATH.'/modules/default/',
'resourceTypes' => array(
'dbtable' => array(
'namespace' => 'Model_DbTable',
'path' => 'models/DbTable',
),
'mappers' => array(
'namespace' => 'Model_Mapper',
'path' => 'models/mappers',
),
'form' => array(
'namespace' => 'Form',
'path' => 'forms',
),
'model' => array(
'namespace' => 'Model',
'path' => 'models',
),
'plugin' => array(
'namespace' => 'Plugin',
'path' => 'plugins',
),
'service' => array(
'namespace' => 'Service',
'path' => 'services',
),
'viewhelper' => array(
'namespace' => 'View_Helper',
'path' => 'views/helpers',
),
'viewfilter' => array(
'namespace' => 'View_Filter',
'path' => 'views/filters',
)
)
));
$al->setDefaultResourceType('model');
}
take a look at this ZF 1 Skeleton for further info:
https://github.com/eddiejaoude/Zend-Framework--Doctrine-ORM--PHPUnit--Ant--Jenkins-CI--TDD-
I don't use modules but here what I do, which is very basic :
In /public/index.php, I add "/forms" to the include path :
(important part is the line with "forms" of course
set_include_path(implode(PATH_SEPARATOR, array(
realpath(APPLICATION_PATH . '/../library'),
realpath(APPLICATION_PATH . '/forms'),
get_include_path(),
)));
My form are then named :
class Default_Form_Login extends Zend_Form
Then I would do :
$form = new Default_Form_Login();

Categories