Yii session have prefix - yii

I am maintaining a Yii application, when i am printing Yii session it looks like this:
Array
(
[cb35f057aa124d26e8793014875ce939_id] => 1
[cb35f057aa124d26e8793014875ce939_name] => admin
[cb35f057aa124d26e8793014875ce939__states] => Array()
[cb35f057aa124d26e8793014875ce939email] => webmaster#example.com
[cb35f057aa124d26e8793014875ce939username] => admin
[cb35f057aa124d26e8793014875ce939create_at] => 2013-01-14 07:44:22
[cb35f057aa124d26e8793014875ce939lastvisit_at] => 2013-09-13 06:09:17
[cb35f057aa124d26e8793014875ce939state_id] => 1
)
i don't know where to find this number cb35f057aa124d26e8793014875ce939 so that i can use session data in my method. it is looks like fixed. does anybody know what is it ?

You should use session variables via Yii API which is
Yii::app()->session['var'] = 'something'; //setting a value
echo Yii::app()->session['var']; //reading a value

this is not session ID, this is application specific prefix which can be found by getStateKeyPrefix()

The above numbers are probably set by calling setStateKeyPrefix() function somewhere in the code.
Here is explanation of the function:
setStateKeyPrefix() - Sets a prefix for the name of the session variables storing user session data.
Additionally, you can use getStateKeyPrefix() function to see weather or not prefix is set.

The prefix is the php session id and u can get it by
Yii::app()->session->getSessionID();

Related

Yii nested URL parameters

Can anyone point me in the right direction in order to write a URL rule in order to achieve the following:
Using the base controller I want to get to each of the parameters in this url:
DomainName/clientID/fileID
Haven't tested it, but this should work:
'rules' => array(
'<clientID:\d+>/<fileID:\d+>' => 'myBaseController/myAction',
)
Just make sure the one rule gets added before your Yii default URL rules. FYI, the rule assumes that both client ID and file ID are integers. If fileID contains letters, change it to fileID:\w+.
$url = $this->createUrl('timeSheetDetaile/create',array('timesheetID'=>$timeSheedID,'dayID'=>1));
first param is the name of your controller and second array is $_GET params ..
have fun.

Insert data from DB to URL manager

I want URL manager to process URL with the company name with my CompanyController. To do so dynamically I should get company names from my database.
Now I have such rule (but it's not dynamic):
'<alias:(vector|karnasch|tecnomagnete|ruko|bds-maschinen|exact)>' => 'company/view',
(vector|karnasch|tecnomagnete|ruko|bds-maschinen|exact) --> data to this line I want to get from database.
I can get this data (manually establish connection to db), but maybe it's another more beautiful solution with help of Yii functional. Thanks!
You can always create your custom UrlRuleclass. If you only want to parse incoming URLs you can simply return false from the createUrl() method. In the parseUrl() method you query the DB for your company names and inspect if the current URL matches. If not, you simply return false again.
Well, you don't need to do this, you just have to define the right pattern, e.g. :
'contact' => 'contact/form',
// other rules should be set before this one
'<alias:[-\w]+>' => 'company/view',
http://www.yiiframework.com/doc/guide/1.1/en/topics.url#using-named-parameters

Authorization::Roles doesn't work in Catalyst app

I've tried use Authorization::Roles in my Catalyst app. Authentication works right but when I use $c->check_user_roles("admin"); it always returns false. What's wrong?
Some config:
store => {
class => 'DBIx::Class',
user_model => 'Mymodel::User',
id_field => 'name',
role_field => 'rolename', # in my table there is the same column
# name undoubtedly
}
If your roles are stored in the users table, use the role_column option. If your roles are stored in a separate table, use the role_relation and role_field options. role_field on its own isn't valid.

Lithium link routing

I am trying to create my first Lithium app and I'm getting a very odd error.
I have a line in my index view,
<td><?php echo $this->html->link($question->title, array('controller'=>'questions','action'=>'view','id'=>$question->id)); ?></td>
Which I would imagine would link to that records view, and using 'questions/view'.$question->id' it does, however, using an array url I get a fatal.
Fatal error: Uncaught exception 'lithium\net\http\RoutingException' with message 'No parameter match found for URL('controller' => 'questions', 'action' => 'view', 'id' => '1').' in /Applications/MAMP/htdocs/learning-lithium/libraries/lithium/net/http/Router.php on line 306
Which to me looks like the router is trying to match the url in the helper, and as it can't, for some reason, it's throwing an exception. Does anyone have any idea's why this is? I'm attacking Lithium from a CakePHP standpoint, so this seems odd to me.
The 'args' param is handled by the default routes and get passed in as arguments to your action method.
Try this:
<?=$this->html->link($question->title, array('Questions::view', 'args' => array($question->id))); ?>
To route it with an id param, you need to specify a route that looks for an id param via {:id}. Look in the default routes.php file for the "Database object routes" section. That has some examples which I'll copy below for completeness:
/**
* ### Database object routes
*
* The routes below are used primarily for accessing database objects, where `{:id}` corresponds to
* the primary key of the database object, and can be accessed in the controller as
* `$this->request->id`.
*
* If you're using a relational database, such as MySQL, SQLite or Postgres, where the primary key
* is an integer, uncomment the routes below to enable URLs like `/posts/edit/1138`,
* `/posts/view/1138.json`, etc.
*/
// Router::connect('/{:controller}/{:action}/{:id:\d+}.{:type}', array('id' => null));
// Router::connect('/{:controller}/{:action}/{:id:\d+}');
/**
* If you're using a document-oriented database, such as CouchDB or MongoDB, or another type of
* database which uses 24-character hexidecimal values as primary keys, uncomment the routes below.
*/
// Router::connect('/{:controller}/{:action}/{:id:[0-9a-f]{24}}.{:type}', array('id' => null));
// Router::connect('/{:controller}/{:action}/{:id:[0-9a-f]{24}}');
So you would need to uncomment one of those two sections depending on what format your ids take. They use regular expressions with the id param to make sure it doesn't match url arguments that aren't ids. Incidentally, the first route is setting the default value for id to null which doesn't exactly make sense to me because I don't think the route will ever match with a null value, but anyway, that is how you set default values for your params.
Note that if you do this, your controller action method needs to look like this:
public function view() {
$id = $this->request->id;
// or an alternative that does the same thing
// $id = $this->request->get("params::id");
// ... etc ...
}
The only way to get url pieces passed in as arguments to your controller action method is to use the 'args' param.
You're not using named parameters in your route, so just output the following in your view:
<?php echo $this->html->link($question->title, array('controller'=>'questions', 'action'=>'view', $question->id));?>
Your function signature in QuestionsController should simply be:
public function view($id) {}

Is it possible to set certain product attributes for a different store view using the Magento API?

We are currently using the Magento API for importing a bunch of products into the store.
But we now run into a problem where some product attributes should be translated into a different language.
And I was wondering if it is possible to do this using the Magento API, because I can't seem to find anything related to that problem.
We currently have 2 store views, 1 for the Dutch version of the site and one for the French version of the site.
Our current import code looks something like this:
$store_id = $soapClient->call($soapSession, 'catalog_product.currentStore', array('nl'));
echo("store_id: $store_id");
$new_product_data = array(
'name' => 'NameInDutch',
'short_description' => 'DescriptionInDutch',
'price' => $price,
'weight' => $weight,
'websites' => array('base'),
'status' => '1'
);
$new_product_id = $soapClient->call($soapSession, 'catalog_product.create', array('simple', 4, $sku, $new_product_data)); // 4 => 'Default' attribute set
$localized_product_data = array(
'name' => 'NameInFrench',
'short_description' => 'DescriptionInFrench'
);
$store_id = $soapClient->call($soapSession, 'catalog_product.currentStore', array('fr'));
echo("store_id: $store_id");
$soapClient->call($soapSession, 'catalog_product.update', array($sku, $localized_product_data ));
Now, the output of the echo statements differs, the first time it's 1 and the second time it's 2, so that doesn't seem to be problem. But apparently it doesn't matter for the API if we set that value.
The result is that on the 'catalog_product.update' call, the name 'NameInFrench' overwrites the default name 'NameInDutch'.
So my question is if something like this is possible using the Magento API, and how one would accomplish this?
Ok, I found the answer, apparently I overlooked a certain line in the Magento API docs, because the solution was right there.
So: you don't need to set the currentStore each time, you just need to append the store id or code to the update array:
$soapClient->call(
$soapSession,
'catalog_product.update',
array($sku, $localized_product_data, 'fr')
);
This works perfectly.