symfony1

Comparing route to current request in Symfony

心不动则不痛 提交于 2019-12-09 19:31:15
问题 For my site navigation I'd like to indicate the current page. If each page in the navigation has its own route is there a way to see if the current request matches the route? Something like: $request->getRoute() == '@my_route' Or, more generally, is there an idiomatic way of setting the active page when creating site navigation in Symfony? 回答1: Or, more generally, is there an idiomatic way of setting the active page when creating site navigation in Symfony? Don't use sfContext::getInstance(),

Set Mime_type validation in Symfony

三世轮回 提交于 2019-12-09 13:58:46
问题 I want to make sure that during file upload time, only the file of the format jpeg, png and gif are allowed. So the "File of type:" below in the screenshot must show jpeg, png and gif: http://lh5.ggpht.com/_SDci0Pf3tzU/ScynOZt_0qI/AAAAAAAAEo0/gMr_zxYofV4/s400/styleerror.png I did the following for my validator in Symfony: $this->setValidator ( 'upload your filehere', new sfValidatorFile ( array ( 'required'=>true, 'mime_types' => array ('image/jpeg, image/png, image/gif' ) ) , array( 'mime

Session deletion in Symfony 1.4

醉酒当歌 提交于 2019-12-09 06:52:35
问题 How do I delete all session variables at once if they are not in Array? PS I set them this way: $this->getUser()->setAttribute('PayPalTransaction.hash', $request->getParameter('hash')); Regards, Roman 回答1: The sfUser class (which you get with $this->getUser() ), keeps all it's attributes in a sfNamespacedParameterHolder . So the setAttribute() function on sfUser if merely a proxy to the sfNamespacedParameterHolder::setAttribute() . You can get the reference to this holder with sfUser:

Clearing Symfony cache for another application

左心房为你撑大大i 提交于 2019-12-09 06:35:18
问题 I would like to clear my frontend application's cache from an action in my backend application. How can I achieve this? 回答1: I believe the proper way to do this in symfony 1.2 is as follows: sfContext::switchTo('frontend'); //switch to the environment you wish to clear sfContext::getInstance()->getViewCacheManager()->getCache()->clean(sfCache::ALL); sfContext::switchTo('backend'); //switch back to the environment you started from 回答2: This works for me. It removes all cached files from the

Symfony app - how to add calculated fields to Propel objects?

爱⌒轻易说出口 提交于 2019-12-09 06:25:05
问题 What is the best way of working with calculated fields of Propel objects? Say I have an object "Customer" that has a corresponding table "customers" and each column corresponds to an attribute of my object. What I would like to do is: add a calculated attribute "Number of completed orders" to my object when using it on View A but not on Views B and C. The calculated attribute is a COUNT() of "Order" objects linked to my "Customer" object via ID. What I can do now is to first select all

Symfony Doctrine Models for Entity Without Primary Keys

冷暖自知 提交于 2019-12-09 03:20:14
问题 I'm working with a legacy database while re-building the web application. I want to use Symfony2.x which obviously has Doctrine as ORM. I've around 50 (mysql) tables which has NO Primary Keys. When I try to generate models, it does not let me do and throw an exception with "No Primary Key on ... table". Do I must have Primary Keys on tables to use Doctrine or is there any way around it? Any help would be great. Thanks. 回答1: Doctrine requires every entity class to have an identifier/primary

Creating user roles

删除回忆录丶 提交于 2019-12-08 19:20:34
I am doing new project in symfony1.4. Now this project requires users to log-in and browse, and as any project of this type requires a way of restricting users based on roles. I don't want to implement this in obvious way, i.e to have roles attribute for each user and have pre-defined roles and assign these to users. The problem with this is it's not very flexible as more roles get defined later. I was thinking on the lines of using an EAV model here, (not sure I can do that in symfony). What you guys think, do you have any better suggestions to make user roles much more flexible when they get

Symfony Method to Turn Template to String

天涯浪子 提交于 2019-12-08 12:02:03
问题 I use the Symfony PHP MVC framework. I'm using JSON to pass an AJAX response, and I need an action's template HTML to be one of the values passed. Does Symfony have a method along the lines of renderTemplateToString() ? Even for those unfamiliar with Symfony, is there an obvious way to do this? 回答1: Use sfAction::getPartial() and getComponent(). 来源: https://stackoverflow.com/questions/1926041/symfony-method-to-turn-template-to-string

Backend sfGuardUser module

爷,独闯天下 提交于 2019-12-08 11:22:45
问题 I use symfony 1.4.11 with Doctrine I have sfGuardUser module in backend. I have sfGuardUserProfile table. sfGuardUserProfile: connection: doctrine tableName: sf_guard_user_profile columns: id: { type: integer(4), primary: true, autoincrement: true } user_id: { type: integer(4), notnull: true } salutation: { type: string(10), notnull: true } first_name: { type: string(30), notnull: true } last_name: { type: string(30), notnull: true } country: { type: string(255), notnull: true } postcode: {

Filter content in Symfony 1.2.x admin generator?

一笑奈何 提交于 2019-12-08 10:35:50
问题 I have a Symfony 1.2.7 application where 3 different sites coexist in the same database. All content has a foreign key, 'site_id', that says which site it belongs to. In my generated admin interface I want to be able to show content from the currently selected site (actually set using a filter class, based on the domain used to access the admin interface). An example: Using 'www.domain.com/admin/', the user has access to content belonging to the 'domain.com' domain (with site_id=1) and this