I am new to YII frame work.
My directory structure is :
Protected >> Modules
I have 2 modules site, admin inside the modules folder
Each module have model, view, controller folders
Config is available inside the protected.
If i open siteurl/admin
then i need to call the admin controller inside the admin module
If i open siteurl/
then i need to calll the site controller inside the site module.
In config i can able to set the default controller. But depending on the url the controller need to change. How to implement this.
I tried the following code
'urlManager'=>array(
'urlFormat'=>'path',
//'showScriptName'=>false,
'rules'=>array(
'admin/' =>'admin/admin',
'admin/login' =>'admin/index/login',
'admin/logout' =>'admin/index/logout',
'admin/<controller:\w+>/<action:\w+>'=>'admin/<controller>/<action>',
I able to call either admin controller or site controller. How to do this. Please help me.
Example:
'rules' => array(
'admin/' => 'admin/admin',
//Call module "Admin" controller "Admin" action "Index" or Default action
'admin/<controller:\w+>/<action:\w+>' => 'admin/<controller>/<action>',
'' => "site/site/idex",
//If empty path call Modue site controller site action "index"
'<action:\w+>' => "site/site/<action>",
enter code here//If empty path call Modue site controller site action <action>
);
Related
For my advanced yii2 project, i added this rule to the common config to support multilanguage view:
'<lang:\w+>/<controller>/<action>' => '<controller>/<action>',
This is working fine, and localhost/en/site/about point to localhost/site/about.
Now i want to hide site controller in the url. I try this:
'<lang:\w+>/<alias:\w+>' => '<lang:\w+>/site/<alias>',
But it does not work. How can I do it?
Thanks
Good day.
I've just started learning ZF2, replicated the Album example step-by-step, and then decided to make it a bit more interesting by adding user registration, and then make the two work together in some way, so i added a new 'Auth' module.
So, when i only had one module in the module list (aside from the Application module) in application.config.php, it was all fine, but when i added the Auth module to the list like so:
'modules' => array('Application', 'Album','Auth',)
i got the following error when trying to access any views from the album module which was working absolutely fine prior to this change:
Zend\View\Renderer\PhpRenderer::render: Unable to render template "album/album/index"; resolver could not resolve to a file
But when i changed the order in which the modules are presented in this array like so:
'modules' => array('Application', 'Auth','Album',)
not a single view (and it has only one) from the Auth module could be rendered, while the Album module was fine.
Zend\View\Renderer\PhpRenderer::render: Unable to render template "auth/user/index"; resolver could not resolve to a file
Both of these views exist at these locations, but the renderer doesn't see them for some reason.
You can see the project's contents here.
Thank you for any tips in advance.
Looks like you copy pasted the the view manager config for Auth module.config.php.
This should be auth rather than album for your templates to work correctly.
'view_manager' => array(
'template_path_stack' => array(
'auth' => __DIR__ . '/../view',
),
),
I'm trying to define RESTful routes for sub directory controllers. I want to be able to create routes for the url at admin/questions/*. My controller is Admin_QuestionsController:
- application
- controllers
-Admin
QuestionsController.php (class Admin_QuestionsController)
Below is how I'm declaring my RESTful route for this controller:
$restRoute = new Zend_Rest_Route($front, array(), array(
'admin' => array('questions')
));
$router->addRoute('rest', $restRoute);
..from the documentation I can't see what I'm doing wrong - http://framework.zend.com/manual/1.12/en/zend.controller.router.html#zend.controller.router.routes.rest. However, I get the following error:
Invalid controller specified (admin)
I can get the routes to work when I declare then not as Rest routes:
$router->addRoute('admin_questions',
new Zend_Controller_Router_Route( '/admin/questions', array(
'controller' => 'Admin_Questions',
'action' => 'index')
)
);
..so I don't think I've have the folder structure wrong, or the class name. But, I need RESTful routes which I'm unable to achieve.
The Zend_Rest_Route route like you have defined, works if you have Zend modules enabled. The documentation mentions "translating the HTTP method and the URI to a module, controller and action". To enable modules, add the following two lines in your application.ini:
resources.modules[] =
resources.frontController.moduleDirectory = APPLICATION_PATH "/modules"
Then create a directory in application/modules named admin/controllers, and create your QuestionsController in application/modules/admin/controllers/QuestionsController.php.
The rest of your application should (hopefully) still work as the default module.
I have just gotten started with the Yii framework, trying to create a simple application. I have added the yii-user-management module (YUM) and have followed the short installation tutorial.
Following the tutorial, I created a RegistrationController that extends the YumRegistrationController - then tried loading it in the browser. However, regardless of how I change the config for UrlManager, I cannot get my own controller or view loaded (the view was copied to protected/views/registration.registration.php as instructed).
I am not the only one with the same problem - see here for example - but I cannot get any of the solutions working. Not even renaming the controller has worked, so I figure that there is something fundamentally wrong with my UrlManager settings.
'urlManager'=>array(
'urlFormat'=>'path',
'showScriptName'=>false,
'caseSensitive'=>false,
'rules'=>array(
'<controller:\w+>/<id:\d+>'=>'<controller>/view',
'<controller:\w+>/<action:\w+>/<id:\d+>'=>'<controller>/<action>',
'<controller:\w+>/<action:\w+>'=>'<controller>/<action>',
),
),
The YumRegistrationController gets loaded every time, or I get a 404 error.
I have tried additional rules, like:
'registration' => 'application.controllers.Registration',
or (after renaming)
'registration' => '//MyRegistration/registration',
and even
'registration' => '//registration/registration/registration',
like in an article I read, but nothing worked.
Please help - I would really love to move on to creating an app instead of just working on the setup...
UPDATE: /registration/registration/registration works, it just shows the default view and loads the controller for YUM registration...
Yii version 1.1.10
I think , you have user component registered in your config main.php. So please share that. I can help.
. 'loginUrl' => array('/user/user/login'), may cause problem. no need to change urlManager.
'user'=>array(
'class'=>'application.components.WebUser',
'allowAutoLogin'=>true,
'loginUrl' => array('/user/login'),
),
If I defined 2 controllers, A.php and B.php, and in each controller I defined an index action,
how should I define Route::set in the bootstrap.php file?
The default route should do just fine:
Route::set('default', '(<controller>(/<action>(/<id>)))')
->defaults(array(
'controller' => 'welcome',
'action' => 'index',
));
Please read the documentation: http://kohanaframework.org/3.2/guide/kohana/routing
That default route will match both controller '/a' and controller '/b', and execute the index action if no other action is specified in the URI.
I have read the documentation and it's not completely clear when and why you would want to create a Route entry.
Basically, a Route entry is needed if you have a URL that does not conform to the normal /controller/action structure. If you have created controller A and controller B both with index actions, you don't need to add routes to bootstrap.php if you are always going to access those actions using the standard URL syntax:
http://www.example.com/A/index
http://www.example.com/B/index
You could leave off "index" since it is the default action if none is specified.
Let's say you want controller A to be the default site controller, meaning that you don't want to have to use A in the URL, you want to use the action right after the domain:
http://www.example.com/index
Then you do need a route to tell Kohana that any URL that is not matched by any routes you have created (or if you have none) should be handled by your default route. You would create this route in bootstrap.php:
Route::set('default', '(<controller>(/<action>(/<id>)))')
->defaults(array(
'controller' => 'A',
'action' => 'index'
));
This says that if a user goes to http://www.example.com, Kohana will use the index action of controller A. If the user goes to http://www.example.com/foo, then Kohana will use the foo action of controller A. Any URL that does not match any other controller will go to the A controller. If a user requests an action that A does not handle, he'll get a 404 exception.
You still have the B controller, so that will work fine without any route. If the user goes to http://www.example.com/B/index, Kohana knows about the B controller in the app so it will go to the index action there.
Your problem may be in .htaccess file in kohana folder.
I needed to change the "RewriteBase" to the Kohana folder ('base_url' from Kohana::init in bootstrap.php file), otherwise I landed in '404 - no object found'.
Then the default route should do just fine.