I’m pretty sure I’m looking in the right direction but cannot find any documentation on how to accomplish this:
When a user goes to a page and has $_GET[‘t’] set, is there a way to append that to all URLs in the system after that(i.e. page.php?t=5, where t=5 is automatically added to every URL)? Since the pages are private, I do not need clean URLs.
take a look at the langurlManager here. It is implementing exactly what you want.
class LangCUrlManager extends CUrlManager
{
public function createUrl($route,$params=array(),$ampersand='&')
{
if (!isset($params['lang']) )
{
// add here the 'lang' param to each url created by yii
$params['lang']=Yii::app()->GetLanguage();
}
return parent::createUrl($route, $params, $ampersand);
}
}
Just curious why you need to do this? What are you trying to achieve, do you need a value available at all points in the application? I mean is the value of t changing or is it like a session var?
Thanks Raoul, that was very helpful!!! Here is the slightly modified code I ended up using:
<?php
class TopidUrlManager extends CUrlManager
{
public function createUrl($route,$params=array(),$ampersand='&')
{
if (isset($_GET['t']) )
{
$params['t'] = $_GET['t'];
}
return parent::createUrl($route, $params, $ampersand);
}
}
?>
The reason I need this to happen is that users can have access to several different projects at the same time (the ‘t’ variable). Within each project, there are documents, other users assigned to that particular project, etc etc. So depending on which project they initially selected, the ‘t’ variable gets verified, then access checks are performed. Once that is completed, all queries run using that ‘t’ variable to find which documents are available within the project.
Hope that explains it! The permissions on this are extremely complex, and the program has already been written procedural style from scratch. Porting it has been difficult, but as I’m understanding more and more of Yii and getting help from the forums its starting to go faster.
… the need you’re describing could maybe be handled by states variables which are stored at the session level and os are persistant betwenne to requests. This way you don’t need to add parameter to the query.
It looks like this :
//set a state
Yii::app()->user->setState('myVariable','myValue');
// get state
$myVariable = Yii::app()->user->getState('myVariable');
You can find more info on the Documentation and of course the API Guide
On the other hand, if you’ve already solved your problem, it’s good to know anyway (for next time )
Your suggestion has resolved the issue. However, one concern that I have is that I would like to define a custom url manager for a module only and now this is across the whole application. At least your suggestion has identified that the custom url manager class works fine and the issue lies with declaring it on a module level. I will have to have a deeper look on how to declare this at a module level only.