I'm using the symfony plugin "sfMultipleAjaxUploadGalleryPlugin", and I would like to modify it's model.
I want to change the "Photo" class, removing the field "title" and adding the fields "description_fr" and "description_en".
I've made the changes in phpmyadmin, and, in the plugin, I've edited the schema, and the models, filters, and forms to reflect the changes.
I've emptied the cache, but I get doctrine errors concerning the new fields. This plugin is like the admin generator, it extends the class "autosomething", created in the cache at runtime.
Any ideas ? Where else could the photos' model be defined ?
Since it is in the plugins/ folder, I can't just recreate everything using the command-line client.
I am afraid the changes in phpMyAdmin are completely useless, since once you will do a build everything in the database will be managed by symfony itself.
You should first make the wanted changes in the schema, then adjust the relevant classes
in the model
sf_plugin_dir/sfMultipleAjaxUploadGalleryPlugin/lib/model/doctrine/Photo.class.php and sf_plugin_dir/sfMultipleAjaxUploadGalleryPlugin/lib/model/doctrine/PhotoTable.class.php,
in the form sf_plugin_dir/sfMultipleAjaxUploadGalleryPlugin/lib/form/doctrine/PhotoForm.class.php
and possibly in the filters sf_plugin_dir/sfMultipleAjaxUploadGalleryPlugin/lib/filter/doctrine/PhotoFormFilter.class.php
and check also possible helpers
in sf_plugin_dir/sfMultipleAjaxUploadGalleryPlugin/lib/helper/.
Then you should check every action/template using the changed Photo model (if any) and adjust accordingly.
Finally empty the cache
symfony cc
be sure the changes are reflected in all the model classes (not really important, but still)
symfony doctrine:clean
rebuild everything
symfony doctrine:build --all --no-confirmation
it should work now.
Related
Actually, i'm a laravel developer, recently moved to yii and i found gii was there. I can create models, controllers and CRUD facilities with gii... and that's great!
But if I a add more fields in a table or simple delete a field in a table I have to recreate model and controller with gii, otherwise it gives error. It's really taking my time. Is there any other way to do it, because I searched it and found nothing so far about it. People are suggesting command line, but using gii, is it possible?
Why don't you just create a gii model again, once a new field is added.By the looks of it if you do not want to write code again then gii will give an option to modify the existing files and add the fields on its own.Simple as that.
But there is an disadvantage to this,if you have made some modifications as in for logic then that will get overridden once you modify the files using gii.But I suggested this because this fits in your business logic or as far as I can grasp it :p
I have a very big problem with symfony module generation as i always make modification in my database (add tables , add columns, changes names, changes columns data-type .....) and i want a good way to build the symfony module without any effect on the modules that i didn't change it and without drop the data in the database... on brief i need to update my symfony module with my changes ONLY.
I think you mean "models" instead of "modules" here.
If this is the case, basically once you've got data in the database that you don't want to drop:
1 - Make any needed changes to your schema.yml
2 - Use MySQL ALTER TABLE etc to make changes directly to your database
3 - Use the following commands to regenerate your models:
symfony doctrine:build --model
symfony doctrine:build --sql
symfony doctrine:build --forms
symfony doctrine:clean-model-files // to clean up old stuff
Assuming you haven't made changes to your base classes (which you shouldn't do), the rebuilding of the models shouldn't break anything. You're basically re-building everything but only the changes you introduced in your schema will be introduced.
Hey.
I'm having a hard time migrating changes I've done i my config/doctrine/schema.yml file.
I added the column age to the user table. Then I did a php symfony doctrine:generate-migrations-diff followed by php symfony doctrine:migrate .
Looking in my database, the column age is now added, without deleting any data.
But, my /lib/model/doctrine/base/BaseUser.class.php is not changed, there is no age field or functions for age . So I also did the command php symfony doctrine:build-model . Finally the model is updated/migrated too.
So I wonder, is this the only way? Seems like a lot of work, and I'm afraid to miss something each time doing it.
Could I go right into phpmyadmin, add changes in the database there and just do a php symfony doctrine:build-schema , and like that skip the migration part (two commands).
Also when the comes to use of models, am I right that /lib/model/doctrine/User.class.php is where I can make functions and such for my User "data class"? Like, making a function isFemale . If not, where would that kind of function be?
This might be a bad question, but why is the model layer inside the /lib/doctrine path? As far as I have learned, you keep modules inside apps, where you create your view and controller. Why should the model be outside. Like this I can make models without attached controller and view?
Thanks.
Why should the model be outside
Because models can be used everywhere in your project, in example, in different applications and modules.
Could I go right into phpmyadmin, add changes in the database there and just do a php symfony doctrine:build-schema , and like that skip the migration part (two commands).
Of course you can, but migrations are a good approach to track your schema when deploying to production or working in team.
Here how I use doctrine migrations (simple use-case):
Add a column age to my User model in schema.yml
./symfony doctrine:generate-migrations-diff. Migration class(-es) have been generated.
./symfony doctrine:migrate. Column age successfully added to table.
./symfony doctrine:build --all-classes. Build forms/filters/models
That's it. The main idea is that doctrine:generate-migrations-diff class:
Gathers information about all your models' structure (php-representation of schema.yml)
Compares your schema.yml and info from (1)
Generates migration classes based on difference
Also when the comes to use of models, am I right that /lib/model/doctrine/User.class.php is where I can make functions and such for my User "data class"? Like, making a function isFemale . If not, where would that kind of function be?
Yes, you can add such method to User model because it's about users.
So heres the scenario:
Currently we have a development site with 3 models. We found we didn't like our initial schema and added a few rows. We re-generated the schema (doctrine:build-sql).
Now it forced us to drop and re-create all the tables and dump back in all the information as no ALTERS were created but rather CREATE statements only. Not a problem...
The big problem came to updating the models. After we ran a build-all and such a few errors popped up i.e. "Widget sort not found" etc. We figured out we needed to rebuild the models. So we can a symfony doctrine:build-models course Course (Course was the table name...course the models). This worked great and fixed the broken links within Symfony.
The downside is all custom code in the actions.class.php file was lost as were customizations to the _form.php page.
My question on this is, how do we store our own actions so they are not lost if you update a models schema? Similarly templates and such are re-generated to but do not hold any customizations.
There surely must be a simple solution to updating a model's schema in symfony?
Found my answer to this. You don't update the module per say but the models of the database. You can change your schema.yml file and do a symfony migration
http://www.slideshare.net/denderello/symfony-live-2010-using-doctrine-migrations
If you just want CRUD/minimal customisation, you can do this with the admin generator:
./symfony doctrine:generate-admin appname Course
A regular module can't be updated once generated without losing customisations - they are intended to be a starting point.
when using scaffolding on a controller the views render fine and the app even attempts to insert the data; the problem is that the scaffold is completely ignoring the relations I'm defining in my model class, in fact it's ignoring the class entirely as I can delete the file and the controller still scaffolds and render the crud from the table.
Has this ever happened to you?
Edit to add:
Ok this just got weirder, I check my naming conventions and they are allright and to make things worse it's not only happening on scaffolding, I just created a simple table: id, name and country_id and it's ignoring my model file here too even without scaffolding.
Added more info for this question here: https://stackoverflow.com/questions/2945879/why-are-some-classes-created-on-the-fly-and-others-arent-in-cakephp-1-2-7
This probably means you have some sort of naming problem with your model and Cake is not using it to begin with, but makes up its own on the fly. Cake's automagic only works if you follow its naming conventions.
It's hard to say without more details though.
Sometimes, Cake caches too much for your own good. Try deleting the contents of the tmp/cache/ dir inside the cake dir structure and see if the errors keep appearing.