i want change my url in cake php /eng/users/ to /users/; i mean when i entered this /eng/users/ cakephp don't show me error like this
*Missing Controller
Error: EngController could not be found.
Error: Create the class "EngController" below in file: "app\Controller\EngController.php" *
both this /eng/users/ and /users/ become same ? any solution?
You are looking for Router.
Read this article: http://book.cakephp.org/2.0/en/development/routing.html#routes-configuration
and especially for the cause of users ur you should add in your /app/Config/routes.php
Router::connect(
'/eng/:controller/*', array('controller' => 'users')
);
the eng can be set to some prefix and so on.
Related
I am trying to edit(edit.cto) on page 2 but after edit it's always redirecting to the index page 1.
How can i redirect on right pagination?
expected->
https://localhost/erp-development/EmployeeMonthlySalaries/index/page:2
getting -> https://localhost/erp-development/EmployeeMonthlySalaries/index/
You can do that using session.
For example in index controller set:
$this->request->session()->write('referer', ($_SERVER['REQUEST_URI'])); //cakephp 3
$this->Session->write('referer', ($_SERVER['REQUEST_URI'])); //cakephp 2
Then in edit controller:
return $this->redirect($this->request->session()->read('referer')); //cakephp 3
return $this->redirect($this->Session->read('referer')); //cakephp 2
Firstly I would recommend not to use named parameters, as they are a CakePHP-only feature and not standard.
I would recommend to use regular GET parameters using:
'Paginator' => array(
'limit' => 15,
'paramType' => 'querystring'
),
in your components definition.
I would then build all URLs using a custom-defined makeUrl() function, or overriding HtmlHelper::link() one, so that they all contain the querystring received.
Your edit action will then have the URL: /controller/edit/?page=2
and you edit action will know how to build the redirect URL /controller/index?page=2
You can simply replace below redirect code where you write your redirect code in controller:
<?php $this->redirect($this->referer()); ?>
I add route like below
Router::connect('/:language/:controller/:action/*',
array(),
array('language' => '[a-z]{3}'));
I have two language src/Locale/jp and onother is src/Locale/fr
After add route configuration I have tried below URL
project/jp/tests/index
It's giving me error JpController not found.
How can I configure route for localization in cakephp 3.
Update :
In before filter I have added below code , but language is not changing
if($this->request->params['language']=='jp'){
Configure::write('Config.language','jp');
}
Have a close look at what you are passing, jp, that's two chars, now look at your regex, it requires exactly {3} chars - consequently, the route will not match.
On a side note, the folder name should be Locale, not local.
i would like to set base 'url' like "codeigniter" and that can be access in all views. I want to get full url like "http://localhost/somepath"
You probably don't need to do that, as the Helpers in Cake do that automatically.
For example, if your app is under http://localhost/somepath, creating a link like this
echo $this->Html->link('home', '/');
will automatically point to http://localhost/somepath
Links to actions work the same way:
echo $this->Html->link('login', ['controller' => 'Users', 'action' => 'login']);
will automatically point to http://localhost/somepath/Users/login
And if you do need to get the url anywhere else than in a view, you can do it like this:
use Cake\Routing\Router;
$path = Router::url('/', true);
In CakePHP 3 You can define "BASE_URL" constant in
yourAppFolder/config/paths.php as
define('BASE_URL', 'www.yoursite.com/');
and use BASE_URL anywhere in your project.
im still noob with cakephp. I want to access an action with a prefix but im being redirected to my current view. how can i do this? Example:
ihave a function like below:
function admin_getID()
{
some codes here...
}
in my link. i accessed it using this html helper:
$this->Html->url(array('action'=>'getID', 'admin'=>true))
note that currently i dont have any prefix and i want to access the action with a prefix.
the url will be used in jQuery.ajax's URL so in the jquery,
jQuery.ajax({
...
url:"Html->url(array("action"=>"getID", "admin"=>true))?>",
...
});
Thank you!
Since in your file core.php you are using the same prefix, for example:
Configure::write('Routing.prefixes', array('admin'));
You should use:
echo $this->Html->link('link', array('action' => 'getID', 'admin' => true));
This will generate the link /admin/{your_controller}/getID.
For the same Controller, but if you want to display to another controller, you must include the controller parameter in the array.
If you're not using the directive Routing.prefixes as I said above, simply add the admin_getID parameter in action value.
I think you are talking about routing. So for example, if you want to define actions for admin like:
admin_index
admin_edit
admin_view
adn have them accessible by
example.com/admin/index
example.com/admin/edit
example.com/admin/view
This is called routing in CakePHP. You can see how this is done here:
http://book.cakephp.org/1.3/en/view/948/Defining-Routes
Update
You can just do this:
<?php echo $this->Html->link('link', array('controller' => '{CONTROLLER_NAME}', 'action' => 'getID', 'admin' => 'true')); ?>
UPDATE 2
You are not echoing your URL. You need to do this:
jQuery.ajax({ ... url:"<?php echo $this->Html->url(array("action"=>"getID", "admin"=>true)); ?>", ... });
If you are not using PHP to render your jQuery, you cannot use cake to generate your URL, you will have to do it manually:
jQuery.ajax({ ... url:"/admin/CONTROLLER/getID", ... });
I'm working on upgrading my project from CakePHP 1.2 to 1.3. In the process, it seems that the "magic" routing for plugins by which a controller name (e.g.: "ForumsController") matching the plugin name (e.g.: "forums") no longer automatically routes to the root of the plugin URL (e.g.: "www.example.com/forums" pointing to plugin "forums", controller "forums", action "index").
The error message given is as follows:
Error: ForumsController could not be found.
Error: Create the class ForumsController below in file: app/controllers/forums_controller.php
<?php
class ForumsController extends AppController {
var $name = 'Forums';
}
?>
In fact, even if I navigate to "www.example.com/forums/forums" or "www.example.com/forums/forums/index", I get the same exact error.
Do I need to explicitly set up routes to every single plugin I use? This seems to destroy a lot of the magic I like about CakePHP. I've only found that doing the following works:
Router::connect('/forums/:action/*', array('plugin' => 'forums', 'controller' => 'forums'));
Router::connect('/forums', array('plugin' => 'forums', 'controller' => 'forums', 'action' => 'index'));
Setting up 2 routes for every single plugin seems like overkill, does it not? Is there a better solution that will cover all my plugins, or at least reduce the number of routes I need to set up for each plugin?
I guess, that topic Configuration-and-application-bootstrapping covers that:
App::build(array(
'plugins' => array('/full/path/to/plugins/', '/next/full/path/to/plugins/')
));
Also take a look at this ticket: http://cakephp.lighthouseapp.com/projects/42648/tickets/750-plugin-route-problem-when-acl-and-auth-components-used#ticket-750-5 (Cake 1.3 had removed magic plugin routes).
You don't have myplugin_app_controller.php in your /app/plugins/myplugin directory.
Just create a file containing following:
<?php
class MypluginAppController extends AppController {
}
?>
And you will have all your plugin's features. :)