CakePHP 1.3 and Link to subdomain - cakephp

I've been to the darkest corners of the internet, searching for an answer to this.
It's such a simple question, but I just can't make a link to a subdomain using Cake's HTML helper. I know that in 2.0, you can do $this->html->link('Subdomain', array('subdomain' => 'hellosub', 'controller' => 'foo', 'action' => 'bar')); but I'm rolling with 1.3..
Thanks :-)

Related

Easy way to add case insensitive routing in CakePHP 2

Router::connect('/(?i:about)', array('controller' => 'pages', 'action'=>'display', 'about'));
used to work in CakePHP 1.2 but it seems to not be working in CakePHP 2.x
The only other solution that I see is to use the options to set a regular expression that will match against the a flag in the rout, but it seems rather convoluted for something so simple:
Router::connect('/:aboutFlag', array('controller' => 'pages', 'action'=>'display', 'about'),array("aboutFlag"=>"[aA]bout"));
Is there an easier solution more akin to how it was done in cake 1.2?
Router::connect('/:aboutFlag', array('controller' => 'pages', 'action'=>'display', 'about'),array("aboutFlag"=>"(?i:about)"));
This stems from the answer posted here

What's the best way to 301 redirect pages in CakePHP?

I have rewritten my site in Cakephp and choosen to keep the new Cakephp structure. I was wondering if I could use routing in Cakephp for 301-routing (permanently moved).
I want to redirect resources.php, languages.php, clips.php, possibly *.php, to /resources/, /languages/, /clips.
Can this type of 301 redirecting be easily done in CakePHP? I could even write a simple admin-interface to add 301-links, e.g. from a MySQL table to easily administer redirects. Or is it better to do this manually via mod_rewrite?
I'm not sure about the best way, but I would first put routing at routes php like:
Router::connect('/resources.php', array(
'controller' => 'resources',
'action' => 'index'
)
);
(and so on)
After that check at start of the action function which route was used, and if *.php route was used do a 301 redirect:
$this->redirect(array('controller' => 'resources', 'action' => 'index'), 301);
I guess there is also "smarter" way to implement this but this was the idea. (use of before_filter etc)
Since CakePhp 2.x there is Router::redirect() method.
So you could add redirection in your routs:
Router::redirect(
'/resources.php',
array(
'controller' => 'resources',
'action' => 'index'
),
array('status' => 301)
);
The third parameter array('status'=>301) is not necessary because 301-redirect is used by default.
See Redirect routing — CakePHP Cookbook v2.x documentation.

CakePHP: full path behind link, can't remove?

Seems simple but I can't figure it out. Every link on my website suddenly shows the path behind the link
Example:
Not a member yet? Please register(/users/register) to add your pitch.
I can't select the path with Firebug to trace where it is coming from. Anyone has an idea? Thanks
UPDATE:
The PHP code for this link is:
echo $html->link('register', array('controller' => 'Users', 'action'=>'register'));
I use the BluePrint CSS Framework
Your problem isn't the style rule. Your problem is that you are linking a print only stylesheet from blueprint as a normal (screen, projection) stylesheet.
You need to make sure your css link has 'media' = 'print' as one of it's attributes.
IE
<?php
....
echo $this->Html->css( array(
join( DS, array( 'blueprint', 'print' )),
'stylesheet',
array( 'media' => 'print' )
);
...
?>
Somewhere in the head section of your layout.
try this...
$this->Html->link(__('register', true), array('controller' => 'Users', 'action' => 'register'));
cakePHP v. 1.3

CakePHP 1.1 "parseExtension" inexsistent

I have a problem with a site in CakePHP 1.1 which is impossible to migrate from version due to the size of the project.
I need to create methods to which call using extensions, for example:
$Route->connect('/xxx.xml', array ('controller' => 'Interactive', 'action' => 'xxx'));
But this does not work and the problem is that Cake 1.1 does not have this function:
Router::parseExtensions('xml');
Has anyone working with cakephp 1.1 had this problem? If so do they know how to fix it?
Thanks.
I'm not 100% familiar of the capabilities of CakePHP 1.1, but have you considered setting up a router to look for something like the following:
/:controller/:action.xml
Then you could control what controller/action it leads to and alter the layout.
You might need to escape the . on .xml.
I would seriously consider upgrading to CakePHP 1.3 and reading the migration docs.
The problem is not the layout, is this:
if i set this router:
$Route->connect('/xxx.xml', array ('controller' => 'Interactive', 'action' => 'xxx'));
or your example:
$Route->connect('/:controller/:xxx.xml', array ('controller' => 'Interactive', 'action' => 'xxx'));
the function called is:
class MuControlController extends AppController {
function xxx.xml() {
}
obiusly this function cant exists.

Routes configuration for named arguments in CakePHP

In my Cake application I have a controller "completed_projects". Its index action takes no arguments and lists some projects. Different pages can be accessed by
example.com/completed_projects/index/page:23 etc.
I want to make the url's like this:
example.com/portfolio/page23
Obviously I need to make some routes for this. I've tried many of them like:
Router::connect('/portfolio/page:num', array('controller' => 'completed_projects', 'action' => 'index'), array('pass'=>'page:num', 'num'=>'[0-9]+'));
and also:
Router::connect('/portfolio/:page:num', array('controller' => 'completed_projects', 'action' => 'index'), array('named'=>'num', 'page'=>'page', 'num'=>'[0-9]+'));
I also tried modifying them again and again but none of them works well.
I am using CakePHP 1.3. Any help will be appreciated.
Router::connect('/portfolio/page:page_num',
array('controller'=>'completed_projects', 'action'=>'index'),
array('page_num'=>'[\d]+')
);
In your controller, access page_num with:
$this->params['page_num'];

Resources