I have a Project model and a Comment model that are connected with has many relationship( project -> comment ).
Im currently using CTimestampBehavior to keep the created and updated fields in sync but i want the project model change update timestamp when a comment is added, changed or deleted. I got several of cases like this in my project and I would just like to know the best way to go about all of this.
Can I use AfterSave() on each model and tell it to update its parent? That would trigger a chain when a comment is updated that would update all the way to the top. Should I do it this way or does Yii have support for this?
To my knowledge Yii does not have support for this feature. Not sure how that should be implemented in the framework either.
Can't really see any negative sides with this, and I'd definitely look into the same approach myself.
Related
I'm currently given a running website, which using Zend-Framework 1.11 (to be precise, 1.11.11) with Doctrine 2.3 on it.
[I know, it's a very-very OLD version, but unfortunately, I can't upgrade it to newer version, since I'm really afraid that it will causing more trouble and destroy this website entirely lol!!]
I'm new with this ZF, but having a bit experience with other framework, such as - Laravel and CodeIgniter.
So, my question is -
How can I add a new table (or column) to an existing database (or table) using ZF-way or CLI-way?
For example - I'm having a Table called Supplier, with 4 columns
id
name
contact
phone
I want to add mobile_phone, a new column. How can I do that?
I need to add a new Table, exactly the same like Supplier above, how can I do that?
I experienced before, to add 2 new tables, BUT I did that manually... and it's such a pain.
Because, I need to create a file, edit the existing Model file (to create a relationships/FK) and then edit the Model Entity, and surprisingly, when I try to create its functionality, like Insert/Update/Delete, it shows me an error, that I need to create a Model Proxy too, which I check, it suppose be auto-generated.
Is there any good way to add that table (or column)? maybe using CLI or else?
Is there a way, to check, IF I can use doctrine-CLI? maybe something like doctrine --v? or something like that
I did try php doctrine list on project root folder and it fails - Could not open input file: doctrine.
I found those questions (maybe) same like here - Add a new column in Doctrine 2 in Zend Framework.
But, to be honest, I really don't know how it works and is that can be executed on project root folder?
I did try check on the details link about doctrine CLI that provided there, but still, I don't understand how to set it up.
On that link too, it drives me to this link, about how to set-up doctrine CLI, but, as I state, I kind of confuse, how I add / create the file.
In summary, I want to know, is there any way, to create a new Table? Like, on Laravel, we can create a new Table using their artisan:make?
And, is there a better way, to add new a Column on the existing Table?
FYI - I can do this syntax on my project root folder zf show version.?, IF, I can use zf syntax to create table and adding new column, I'm okay with that too. :)
Thanks in advance & Cheers! :)
I'm really sorry, if this thread/question is too long or not a straight-forward question, as I'm getting frustrated, to find a good documentation about this old ZF version
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
Is there a reason why Create and Update are distinct when making MVC application in PHP?
I see why they are distinct in theoretical explanations, but is it worth keeping separate actions and views for create and update in CRUD controller? If I only need to change the title of save button it seems logical to have one action for both create and update operations. which will save object as new DB row or update existing depending on the id it has (or hasn't).
PS. I've always merged them into one action and recently when started searching for information about Zend Framework I've found that every tutorial with some CRUD functionality has distinct create and update actions and views that have almost the same code. It seems strange why authors copy-paste 90% of the code from one method to another.
I think you're asking more of a style question than a purely functional one. For me it's separation of concerns - there is no guarantee that create and update will truly overlap, and there may well be functional differences, so it's a potential landmine in the future to lump them together.
I'm using Codeigniter to flesh out a pretty large project (especially for a n00b). One issue I'm having is how to organise my files and methods. I've broken my project down into features - the app is a task management software so already we have basic features such as "Task", "Project", "User" etc.
The way I intend to do this is by creating controllers for each and then following CRUD methodology in each. So for example in Task we would have the following methods:
create()
read()
update()
delete()
This makes sense in my head. Now in terms of Views, should I have multiple views, or should I combine create and update into the same form? Also, where does non-View functionality go, such as setting cookies etc?
This is quite a specific question but if anybody has any more holistic guides on general structure convention for CodeIgniter projects I'd be very grateful.
I'd say you got it right. This is what I do.
I tend to use the same view for create and update, keep it DRY (don't repeat yourself) if you can.
Non-view related stuff that does not handle anything business-related goes in what I call helper-classes. If it's business related, I put all the logic into services, so I can unit-test them without being dependant of any framework (not sure how new you are at this, but oh well :) ).
You can also use Grocery Crud, a library that provides out of the box CRUD functionality for codeigniter.
It handles pretty good 1->n and n->n relationships so its convenient for small projects.
I don't know if you are familiar with it. If not give it a try. It will save you tons of time and effort.
My controller consists of these methods, which follows REST API guidelines:
read -> get all records.
find -> find record by primary key/id.
create -> show the form view.
store -> insert data from the form into the database.
edit -> show the form view, populated with current records' data.
update -> update data from the form into the database.
delete -> delete data from the database.
This is called Resourceful Controllers.
Yes, you can combine create and edit in same form. However, there are cases those require you to use different create and edit form. In that case, just make 2 separate forms.
And... like #Theodore suggested, GroceryCRUD is worth a try if you don't need too many customizations.
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.