I am working on cakephp project. I have removed index.php from URL using .htaccess file and now I want to remove view name from URL & add some other two varying parameter. Suppose I choose country & city then these two parameter should appear in URL on selecting them.
The problem I am facing is as cakephp takes
www.example.com/Controllername/viewname
But my requirement is like this
www.example.com/Controllername/param1/param2
If I pass this way It looks for param1 as controller and param2 as view.
Initially should be like:
www.example.com/Controllername/
In your APP/routes.php:
// www.example/com/Controllername
Router::connect('/Controllername',
array('controller'=>'Controllername', 'action'=>'index'));
// www.example.com/Controllername/param1/param2
Router::connect('/Controllername/:param1/:param2',
array('controller'=>'Controllername', 'action'=>'index'),
array('pass' => array('param1', 'param2')));
and your controller:
// set to null/a value to prevent missing parameter errors
public function index($param1=null, $param2=null) {
//echo $param1 . ' and ' . $param2;
}
When generating links:
array('controller'=>'Controllername', 'action'=>'index', 'param1'=>'foo', 'param2'=>'bar');
Order matters. Change paramX to anything you want i.e. country and town
note this does not cover: controllername/param1 - both must be present in this example.
There are other ways to achieve this.
I think you should first make sure that mod-rewrite module is enabled. You shouldn't have had to remove index.php from the url using .htaccess if mod_rewrite were enabled. Check how to enable it in the manual of your webserver and the default .htaccess of cakephp should be able to handle the rest of the routing for you.
After you have enable rewrite module, you can modify the routes as pointed out by #Ross in the previous answer in you APP/routes.php:
// www.example/com/Controllername
Router::connect('/Controllername',
array('controller'=>'Controllername', 'action'=>'index'));
// www.example.com/Controllername/param1/param2
Router::connect('/Controllername/:param1/:param2',
array('controller'=>'Controllername', 'action'=>'index'),
array('pass' => array('param1', 'param2')));
Related
I have created CRUD for global configuration parameters. I want to apply this parameters value as main config params (main.php).
I have found some way like add value of these parameters to any .inc file and perform read/write operation. Can anybody help me how can I achieve this? I am beginner in yii.
I have created table structure :
global_config :
Field | Value
pageSize | 20
admin_email| admin#example.com
main.php file as below :
.
.
{
'params' = array(
'pageSize' => 10,
'admin_email' => 'admin#example.com',
);
}
.
.
I am using config file as show above, I want to change it dynamically that it should get value from database.
So that I can make changes in config file from front-end side. I don't need to perform open/write action on main.php
In yii1 you can use params you can set this in main.php
'params'=>array(
'your_param'=>'your_value ',
...
Yii::app()->params['your_param'];
and you can set this value like a simple array poplulating the value form database
$param['yuor_param' =>$your_db_value];
You can't do this for params. As Application parameters are not really meant to be altered and if you change a value, it does not persist across different requests.
These are treated as constant in Yii, So you can't define them after running the script as config files runs at first as your code runs.
Finally, I found solution as per my requirement. I followed given below link from yii forum.
Link : http://www.yiiframework.com/wiki/304/setting-application-parameters-dynamically-in-the-back-end/
Thanks.
we're using codeigniter framework to build application, but we're facing problem to configure '$route' to send correct request.
we just need to setup these route properly.
How i access category:
Category: http://localhost/codeigniter/category/'category-name'/
$route['category/(:any)'] = 'category/index/$1';
Category Post List By Alphabet:
Category Page by List: http://localhost/codeigniter/category/'category-name'/list/'A'/
$route['category/(:any)/lists/(:any)/'] = 'category/lists/$1';
How i access pages:
Page: http://localhost/codeigniter/page/'category-name'/'page-name'/
$route['page/(:any)'] = 'page/index/$1/$2';
we're using rotue something like that, maybe we have problem in it, please check these and let me know how to fix that.
In our codeingiter installation we are using 'codeigniter' dir, 'category' AND 'page' are controllers. in single quotes we are sending values.
Try like
$route['page/(:any)/(:any)'] = 'page/index/$1/$2';
And
$route['category/(:any)/lists/(:any)/'] = 'category/lists/$1/$2';// But Iam not sure
$route['category/(:any)'] = 'category/index/$1';
How to get parameters from below url
domain.com/admin/edit/12
I want to access this value (12) in edit function.
I searched around but didn't found any inbuilt solution in zend framework.
Even in other framework it works easily.
Like in codeIgnitor it works as segment and function parameter.
How I can see from code , you have Admin_Controller & some action edit ( by default routing) . For getting edit value , U need generate urls like domain.com/admin/edit/id/12/ (for example) . And than in action edit use next:
$id = $this->_request->getParam('id',0);
if ($id){
//get info for edit by ID
}
EDIT
IF you still want urls like domain.com/admin/edit/12, do next:
$uri = $this->_request->getRequestUri(); // or $this->getRequest()->getRequestUri()
$id = intval(end(explode('/',$uri)));
if($id){
// do something
}
i have a view (grid) which is used as a rendepatial. this renderpartial grid is used in two actions.
<div id="activities"><?php echo $this->renderPartial('grid', array('model'=>$model)); ?></div>
i would need to know how can i check which action is requesting now ? i need to stop some scripts generating from yii and add some scripts when action is 'default/index/' (i mean the call is coming from default/index/) this could also be called from this way ... search/default/index/area/act?query=
action A - http://mylocalurl.com/ijob-css/index.php/search/default/index/area/act?query=
action B - http://mylocalurl.com/ijob-css/index.php/activities/default/index/
for action b only i need to add some scripts and wondering how this can be done in yii ?
is there something like this available in yii ? if(yii->app->getRquest == 'action B')
EDIT 1
I tried it this way,
echo Yii::app()->controller->action->id . " - " . Yii::app()->controller->id . " - " . Yii::app()->controller->module->id;
it returns, //sessionIndex - default - activities from both actions.
but what i wanted to do is, from where did user come to this path ? his last URL.
so i can easily track weather its action 1 or action 2
EDIT 2
tried this way too, echo Yii::app()->user->returnUrl;
but it prints onlty - /ijob-css/index.php
EDIT 3
This does that but need to know is there any better way to get it ? $_SERVER['HTTP_REFERER']; also this retuns the entire url like this http://mylocalurl.com/ijob-css/index.php/search/default/index/area/act?query=
but i only needed "search/default/index/area/act?query=" in fact the model id is even fine alone which is "search"
To get action ID use:
Yii::app()->controller->action->id
Similar for controller:
Yii::app()->controller->id
And for module use:
Yii::app()->controller->module->id
You can also use:
Yii::app()->request->pathInfo
For Yii preprocessed path info
$route = Yii::app()->getUrlManager()->parseUrl(Yii::app()->getRequest());
echo $route;
But module, controller, action can be deleted, I advice to give addition parameter to grid
$this->renderPartial('grid', compact(
'model',
'flag'
));
//grid
switch($flag) {
...
}
About a week ago, I was working in a test environment for a new site. I left for an hour, came back, and now cannot get to the admin page, as in ‘http://magento.localhost.com/admin’ results in a No Route 404. I am the only one with access to this, it is not live in any sense. I am using VBox with Ubuntu to host the environment. In terms of possible fixes, so far I have tried…
Making sure core_store, core_store_group, core_website, and customer_group table ids are set to 0 (as described in this and many other articles - http://www.nude-webdesign.com/fix-for-magento-admin-error-404-page-not-found/)
Playing with the /app/code/core/Mage/Core/Controller/Varien/Front.php method _isAdminFrontNameMatched to display the adminPath (it’s ‘admin’)
Cleared the var folder, emptied browser cache. Site’s caching was and is turned off.
Adding 'index.php' to the url still results in a 404.
As per Magento Admin 404, the file 'app/etc/use_cache.ser' doesn't exist for me.
On the day of this occurring, I was simply playing around with some layout files I had copied to a module I made and the theme’s media queries (all of which were reverted to their original state even before this problem started to occur).
Does anyone have any suggestions as to what is wrong here? Any other possible reasons this could be happening?
Thanks for anything.
EDIT 1:06pm 9/10/2013: In response to Alan Storm's method of retrieving controller names that Standard.php is looking for, I was returned many "missing" controller files. However, after downloading a fresh copy of 1.7.0.2 to find those files, they weren't present in their either. Here is my output from Alan's var_dump suggestion in Standard.php:
..."/public_html/app/code/core/Mage/Index/controllers/Adminhtml/Controller.php"
..."/public_html/app/code/core/Mage/Paygate/controllers/Adminhtml/Controller.php"
..."/public_html/app/code/core/Mage/Paypal/controllers/Adminhtml/Controller.php"
..."/public_html/app/code/core/Mage/Widget/controllers/Adminhtml/Controller.php"
..."/public_html/app/code/core/Mage/Oauth/controllers/Adminhtml/Controller.php"
..."/public_html/app/code/core/Mage/Authorizenet/controllers/Adminhtml/Controller.php"
..."/public_html/app/code/core/Mage/Bundle/controllers/Adminhtml/Controller.php"
..."/public_html/app/code/core/Mage/Centinel/controllers/Adminhtml/Controller.php"
..."/public_html/app/code/core/Mage/Compiler/controllers/Adminhtml/Controller.php"
..."/public_html/app/code/core/Mage/Connect/controllers/Adminhtml/Controller.php"
..."/public_html/app/code/core/Mage/Downloadable/controllers/Adminhtml/Controller.php"
..."/public_html/app/code/core/Mage/ImportExport/controllers/Adminhtml/Controller.php"
..."/public_html/app/code/core/Mage/Api2/controllers/Adminhtml/Controller.php"
..."/public_html/app/code/core/Mage/PageCache/controllers/Adminhtml/Controller.php"
..."/public_html/app/code/core/Mage/XmlConnect/controllers/Adminhtml/Controller.php"
..."/public_html/app/code/core/Mage/Adminhtml/controllers/Controller.php"
..."/public_html/app/code/community/Phoenix/Moneybookers/controllers/Controller.php"
..."/public_html/app/code/core/Mage/Captcha/controllers/Adminhtml/Controller.php"
..."/public_html/app/code/core/Mage/CurrencySymbol/controllers/Adminhtml/Controller.php"
..."/public_html/app/code/core/Mage/CurrencySymbol/controllers/Adminhtml/IndexController.php"
Resolved 3:39pm 9/10/2013: Ok, it's fixed albeit rather bluntly. I took the output of Alan Storm's var_dump suggestion to mean I had created an error somewhere in the core code pool (which is not something I intended on doing, screwing with the default code that is). Unfortunately for sake of exact learning, I then replaced it all with the default core code pool of 1.7.0.2. This was done before Alan updated his original answer with more suggestions that I never investigated. Thanks Alan, you're rad.
A no route 404 error usually indicates Magento can't find the controller file it thinks it should load (usually due to a misconfiguration)
The easiest way to diagnose this is to hop to _validateControllerClassName
#File: app/code/core/Mage/Core/Controller/Varien/Router/Standard.php
protected function _validateControllerClassName($realModule, $controller)
{
$controllerFileName = $this->getControllerFileName($realModule, $controller);
if (!$this->validateControllerFileName($controllerFileName)) {
return false;
}
$controllerClassName = $this->getControllerClassName($realModule, $controller);
if (!$controllerClassName) {
return false;
}
// include controller file if needed
if (!$this->_includeControllerClass($controllerFileName, $controllerClassName)) {
return false;
}
return $controllerClassName;
}
and drop some logging or var_dumps around the return false statments. This should tell you which files Magento is looking for and can't find — it's usually enough to point to the problem.
if (!$this->validateControllerFileName($controllerFileName)) {
var_dump($controllerFileName);
return false;
}
$controllerClassName = $this->getControllerClassName($realModule, $controller);
if (!$controllerClassName) {
var_dump($controllerClassName);
return false;
}
// include controller file if needed
if (!$this->_includeControllerClass($controllerFileName, $controllerClassName)) {
var_dump("Couldn't include: $controllerFileName");
return false;
}
Update: It's normal for Magento look for the controller file in multiple places — every module that registered as containing adminhtml controller files needs to be checked.
However, almost all the controller files being looked for are named /Controller.php. For the default /admin index page this should be IndexController.php. This makes me think your system thinks it's supposed to look for a controller with a blank name, (likely the default controller value since /admin (and not admin/index) is the URL you're using)
There's myriad reasons this could happen — many revolving around a core file being changed or a configuration node in a module set to the wrong value. If the solutions below don't work for you you'll need to try diff-ing your code base vs. a clean one, disabling every custom module and if that fixing things turn modules back on until the problem module is found, or dive deep into debugging Magento routing code to figure out why your system is unhappy.
One common cause for this behavior is an invalid value (or no value at all) being set for a custom admin path at
System -> Configuration -> Admin -> Admin Base URL -> Use Custom Admin Path
If the value for "custom admin path" is blank, or contains and additional /, this could be interfering with the routing.
Since you can't access the admin, try running the following SQL query
select * from core_config_data where path like '%custom_path%';
...
292 default 0 admin/url/use_custom_path 1
293 default 0 admin/url/custom_path admin/
If you see results similar to the above, or admin/url/custom_path is blank/not-present but admin/url/use_custom_path is still 1 — then that's your problem.
Try deleting these configuration values (admin/url/use_custom_path) and (admin/url/use_custom_path) from core_config_data.
If that doesn't apply to your system, per my blank controller theroy my best guess would be for some unknown reason the code at
#File: app/code/core/Mage/Core/Controller/Varien/Router/Admin.php
public function fetchDefault()
{
// set defaults
$d = explode('/', $this->_getDefaultPath());
$this->getFront()->setDefault(array(
'module' => !empty($d[0]) ? $d[0] : '',
'controller' => !empty($d[1]) ? $d[1] : 'index',
'action' => !empty($d[2]) ? $d[2] : 'index'
));
}
is populating the controller key with a blank value.
In my case, my admin was giving me 404 because there's no store set.
I solved it by running the following query
SET SQL_SAFE_UPDATES=0;
SET FOREIGN_KEY_CHECKS=0;
UPDATE `core_store` SET store_id = 0 WHERE code='admin';
UPDATE `core_store_group` SET group_id = 0 WHERE name='Default';
UPDATE `core_website` SET website_id = 0 WHERE code='admin';
UPDATE `customer_group` SET customer_group_id = 0 WHERE customer_group_code='NOT LOGGED IN';
SET FOREIGN_KEY_CHECKS=1;
SET SQL_SAFE_UPDATES=1;
You can check if you get the below error logged in var/log/system.log
ERR (3): Recoverable Error: Argument 1 passed to Mage_Core_Model_Store::setWebsite() must be an instance of Mage_Core_Model_Website, null given, called in /.../app/code/core/Mage/Core/Model/App.php on line 634 and defined in /.../app/code/core/Mage/Core/Model/Store.php on line 395
Before anything check your configuration file ( app/etc/local.xml) and make sure that you have "admin" as value for the frontName tag.
ex.:
<adminhtml>
<args>
<frontName><![CDATA[admin]]></frontName>
</args>
</adminhtml>
Usually when you try http://yoursite.com/admin it gives you the admin area
Try using an url like that http://yoursite.com/index.php/admin
and if it works probably you need to only modify the rewrite rules or follow the suggestions (see the link below)
I got this problem on a shop with custom admin url www.shop.com/customadminroute/ and System -> Configuration -> Web -> URL options -> Add Store Code to Urls: Enabled
In this case the following module should fix it:
https://github.com/romfr/404adminlogin
Thanks to Blog post of Carmen Bremen:
http://neoshops.de/2012/09/07/magento-404-fehlerseite-beim-admin-login/