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.
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'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.
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.
What I have is the following db structure(tables):
lists[name,id]
list_items[title,list_id,content]
I've created the needed files and code(the MVC) needed to manage the first table(lists).
I also added the hasMany to the model class. At that point I am stuck.
What I need is a solution for managing each item (basic CRUD, I assume that complex management is just an advanced CRUD that I will find out how to do by myself).
I will be specific: since it's a content that have no place (but the admin) that it will be used by itself, should I -
create a full mvc structure for it? (can or should I implement it somehow[how?] in the lists package?
if not, how can I attach the tables? (since the use is about to be dropped in version 2)
would an element(cake concept/context) will be the appropriate way to create a view for such situation?
ANY insight will be appreciated.
If I undertant correctly, you want to create a CRUD part of this tables by yourself, without bake.
You need to write all the MVC estrucure and be carefull with the naming combention of cakephp http://cakebaker.42dh.com/2006/02/18/cakephp-conventions/
You need the model into app/models and also a a controller into app/controllers (remember naming combentions) and for each model you need a folder into /app/views.
Alfo, every, every function in your controller needs a view, even if this action doesn´t write anything to screen
I hope this was usefull.
Have you tried using Cake's bake feature? Your CRUD will be automatically created in about 2 seconds. I would also recommend you do the Blog tutorial to get a feel for scaffolding.
CakePHP is all about convention over configuration. Eg naming conventions for tables, controllers, models etc.. So much can be done automagically.