How do I connect to a view in a subfolder in cakephp 1.3?
If I organize folders in my Views like:
Views/my_folder/my_subfolder/mypage.ctp
How do I connect to the mypage.ctp view in routes? I've tried the following:
Router::connect('/my_folder/my_subfolder/mypage',
array('controller' => 'my_folder', 'action' => 'mypage'));
The above does not work. Is there a different way to write the connection in routes.php?
I want the url to be: www.mysite.com/my_folder/my_subfolder
the Pages controller looks for views in Views/Pages
so move your mypage.ctp there.
The structure of Views folder is guided by conventions, mapping from url to controller+action is the only thing that you change via routes.
Please check it
Router::connect( '/foldername', array('controller' => 'controllername', 'action' => 'functionname'));
Related
I have a route:
Route::set('foo/subdir', '<directory>/<variable>/subdir/<controller>/<action>');
I would like to route this url to the following controller/action:
/application/classes/<directory>/subdir/<controller>.php::action_<action>()
I already have and need this route too, which complicates things:
Route::set('foo', '<controller>/<variable>/<action>');
Is that possible?
Why not, as long as the default route is defined after the directory route.
Route::set('foo/subdir', '<directory>/<variable>/subdir/<controller>/<action>')
->defaults(array(
'directory' => 'default_directory',
'controller' => 'index',
'variable' => 'default_variable',
'action' => 'index',
));
Kohanas routing supports directories 'natively', there is no need to hack anything.
Please note your class names will have to include the directory name as well.
I would like to append the subdir to the directory
This will be possible in Kohana v3.3 using the new Route::filter functionality. There is currently no way to do this in Kohana 3.1 or 3.2 without modifying the Route and/or Request classes.
Use REGEXP to catch directory and subdirectory as /directory/subdirectory/controller/action
to match Route like // where regexp allows you to put / inside directory. Then make little modification in your Route class to change all / to the _
It is not tested ... yet. ;) But im about to...
I'm try to create search engine friendly URLs for the pages controller, i.e. /about instead of /pages/about.
I've tried setting up the following routes (at the bottom of routes.php):
Router::connect('/*', array('controller' => 'pages', 'action' => 'display'));
and
Router::connect('/:page', array('controller' => 'pages',
'action' => 'display'), array('pass' => array('page'), 'page' => '[a-z]+'));
Both properly match /about, /support, etc. However, failed when I had a action/method pair. For example, /contact should route to PagesController->contact(). However, the above routed it to PagesController->display().
There has to be a way to accomplish this without making a specific route for each page. How can I create a route or set of routes that:
Mimics the default route behavior for
the PagesController. That is routes
to display() unless a action/method
pair exists.
Does so with search engine friendly URL. That is coming from root / not /pages.
Demonstrate both the Router::connect() and Html->link()
I have checked for examples in the CakePHP Book and viewed other questions such as CakePHP routing in pages controller. Nothing seems to satisfy the specification above.
You need to create a second route for the contact method call and put it before the more generic rule to match "everything [a-z] after /pages". Try that before your rule:
Router::connect('/contact', array('controller' => 'pages', 'action' => 'contact'));
Always keep in mind that the order of routes is important. The more generic a rule is the more will it match. So put more specific rules in front of the more generic ones.
I have a problem with the url rewriting.
The problem that I am facing is that currently our urls are like this:
http://www.xyz.com/sc_users/index
I dont want the controller name to be shown in that url.
Is there a way to achieve that??
First of all thank your guys..
Like I have 8 controllers I dont want the controller name to be shown in my url....this is what I want..
To be more precise no controller name in my url
You can define custom routes in app/config/routes.php. You'll find the all about routes in the CakePHP cookbook under Defining Routes. For example, a custom route can look like this:
Router::connect(
'/the_url_you_want_to_use/*', array('controller' => 'sc_users', 'action' => 'index')
);
You need to read up about CakePHP routing, look at the examples under 'defining routes'. Update your question with what you would actually like your URLs to look like and we will be able to help you more effectively.
That's simple :
there is a file called routes.php in /config directory :
You can do url rewriting stuff there like this :
Router::connect('/pages/*', array('controller' => 'cmsPage', 'action' => 'render'));
You can pass more complicated variables to your controller :
Router::connect('/:id-:lang-:profile-:firstName-:lastName-:profile.htm',
array('controller' => 'profiles','action' => 'view'),
array('id'=>'[0-9]*', 'lang'=>'fr','firstName'=>'[^-]*','lastNAme'=>'[^-]*','profile' => $util->keywords['profiles'][0]['fr'], 'pass' => array('id', 'lang'),'profile' => $util->keywords2['profiles'][0]['en'])
)
;
As you can see in the last example I have passed 2 parameters to the controller through 'pass' => array('id', 'lang')
I have created a cakephp app. I have urls looks like
www.mysite.com/products/search/hardware
It loads fine. But I want urls that looks like
www.mysite.com/hardware
Can this is achieved by setting route connect
I appreciate any help.
Thanks.
Yes, you can use a route.
Router::connect(
'/hardware',
array('controller' => 'products', 'action' => 'search', 'hardware')
);
For a more general solution (any category name routing to products/search) see http://book.cakephp.org/view/948/Defining-Routes
You could add something like
Router::connect('/hardware',
array('controller' => 'products', 'action' => 'search'),
array('pass' => array('search'), 'search' => 'hardware'));
in your routes.php file, but then you would have to do it for each searchable item.
The problem you will be facing if you want something automatic, is that you need a way to differentiate your searchable products from every other model you have. So maybe you should settle for another type of URL like
www.mysite.com/products/hardware
or
www.mysite.com/s/hardware
and use the appropriate routes accordingly.
How about creating hardware_controller in your controllers folder.
I want to make a kind of alias for my modules:
Is there a way to make
http://www.example.com/news point to
/modules/news/controller/news/->action
index.
And if i go to
http://www.example.com/news/show it
automaticly points to
/modules/news/controller/news/ ->
action show
Or do I have to make a route for every single action I make in this module?
If I don't make a route my links will look like:
http://www.example.com/news/news/show and http://www.example.com/news/news/show.
P.s i'm using Zend 1.10.6
Thanx in advance!
I guess it will be something like that:
$route = new Zend_Controller_Router_Route(
'news',
array('module' => 'news', 'controller' => 'news', 'action' => 'index'));
$router->addRoute('news', $route);
where first arg 'news' for Zend_Controller_Router_Route is the url http://www.example.com/news that will route to http://www.example.com/news/news/index
salu2
In your config file you must enable modules by putting this in your config file
resources.modules[] =
And it should by default route correctly in your application.
You will have to define a route for each URL you want routed in a non-standard way.