I would need an idea or two how I would do this in cakephp (using latest version)
I am building a web based game where you will be able to collect Items
Without a framework I would have an abstract base item class that every item would extend to
And when displaying for example a inventory i would factory all items the user currently have and then return a object for each item.
classes...
BaseItem
WeaponItem
HealingItem
etc..
How would I do this in cakephp? Would I go for a model for each item class ... and how would i factor to get the object? ...
Assuming you're using a database as the data store, presumably you will use a single table for all items the player can collect? If so, you probably want a single Model class.
It's possible to have an inheritance hierarchy for models in CakePHP if you want. But you can often achieve sharing of Model logic using a Behaviour.
Related
I have three entities:
class DataSet {
string $name;
Collection $points; // List<DataPoint>
Collection $groups; // List<DataGroup>
}
class DataGroup {
string $name;
Collection $assignedPoints; // List<DataGroupPoint>
}
class DataPoint {
string $name;
Collection $assignedGroups; // List<DataGroupPoint>
}
class DataGroupPoint {
DataGroup $group;
DataPoint $point;
int $data;
}
I extended the Admin UI to perform CRUD operations on the DataSet entity, as per docs. By looking at the ContactBundle Javascript extension, I was able to add CRUD operations for DataPoint entities within the DataSet form by registering a CardCollection - works fine.
Now, I want to perform CRUD operations on associated DataGroup entities of the DataSet as well - for that I want to put a MultiItemSelection component into the DataGroup overlay form in order to add, edit or remove DataGroupPoints.
For a DataGroupPoint entity, both the DataGroup and the DataPoint are supposed to belong to the same DataSet (which in turn is being edited in the overall form).
How can I provide all matching DataPoint entities to the MultiItemSelection?
As far as I understand your question, you are looking for a custom data_point_selection content type.
To achieve this I can recommend you to take a look at the Sulu Workshop, especially assignment 11. In this assignment a single_location_selection is implemented. This is a selection for the custom entity location.
Another great example for a custom selection or single_selection is the example pull request of the sulu demo.
As a side note, the implementation of the ContactBundle is very specific for this case. Therefore the extendability and usability of the used components like CardCollection is not the best. For a better developer experience I would recommend you to stick to the documented content types in the docs. Unless you really need these specific components.
I need an advice for my application. I have fleet with Vehicles and every vehicle has its owner. I would like to have possibility to add "Items" to these vehicles such as Insurance etc.
http://s27.postimg.org/c4hb8o02r/screens.jpg
I would like to click on the icon and have a list of items for this vehicle.
Should I create a methods for this within Vehicles Controller or create another one?
The "Items" are different database entities than the Vehicles. You will probably end up doing other actions with those "Items" in the future beyond viewing them (e.g. Create/Edit/Update).
You'll want to manage different database entities separately in an MVC framework.
So yes, create an ItemsController. You can then code a "getItemsByVehicleId" method and build out the View to display them.
I need a custom query pagination in CakePHP 1.2.
I have a reviews model and on one set of pages, it paginates the reviews model one way, and on another set of pages it does it another way with a different custom query. How do I overwrite paginate and paginateCount twice in the same model?
IMHO
I wouldn't do it in the same model.
I would have two different models with different overwrites depending on your requirements and use them in the paginate method accordingly.
Something like.
$this->paginate('Superreviews');
$this->paginate('Normalreviews');
Obviously in both model classes you would have:
var $name = 'Review';
HTH
I would like to create a Group model in Google App Engine and then have an attribute where I can create a list of UserReferences. The documentation said:
"A property can have multiple values, represented in the datastore API as a Python list. The list can contain values of any of the value types supported by the datastore."
Would I implement this by creating:
class Group(db.Model):
group_list = db.ListProperty(users.User)
Or might I be better served by simply listing the user entity keys?
http://code.google.com/appengine/docs/python/datastore/entitiesandmodels.html
keys are better placed in ReferenceProperty and their purpose is to create relationships between two kinds.
You can simply create the listproperty and as your list grows keep adding listitems to it.
class Group(db.Model):
group_list = db.ListProperty()
This depends on your use-case. If you already have a User model, to store additional data about your users, then using a db.ListProperty(Key) for User model keys is probably your best option.
I have a table in my database called "Task". Task has the following fields:
- ID
- Description
- AssignedUserID
- TaskTypeID
I am accessing this table through a class that was created automatically after I used an ADO.NET Entity Data Model. I can load and show the fields mentioned above in a DataGrid in my Silverlight application. However, AssignedUserID and TaskTypeID are not very descriptive. So I decided to create a stored procedure that gets the tasks and the user and task type names through their respective lookup tables. This is where the problem lies.
I want to create some custom properties in the automatically generated "Task" class. The custom properties would be named "AssignedUserName" and "TaskType". I then want to make these properties available to my Silverlight client. However, I cannot seem to figure out how to get them exposed to my Silverlight client.
Can someone help?
Thank you
If your EDM is in the same project as the DomainService you can do this:
create a partial class on the Entity type, and add your calculated property in there.
name the file **.shared.cs
it will then be auto-shared with the client/Silverlight code.
Edit:
I was assuming that you could do this calculation in app logic rather than use an sp, which seems more straightforward to me.
If you do use an SP, you'll need to use the Function Import feature in the designer to map the SP to a function in the EDM. This function can then return entities, with properties mapped however you like.
An easier way would be to just use the object model: Have Task.AssignedUser and Task.TaskType objects off of your Task class. Map these to lookup tables in your db. This will work out-of-the box (assuming the Id's are FK's to those lookup tables).
So, a couple options:
use app-logic--properties in a partial class to return the descriptions
use the object model driven by FKs to lookup tables, then just access Task.AssignedUser.Name or Task.TaskType.Description
use a function import to access the SP and map the returned values to entity properties
1 or 2 being the best options IMHO.
Another approach might be to update your EF model to include the lookup tables, add Associations between the tables, add [Include]s in the (auto-gen'd) metadata class and let EF and RIA do it for you. Maybe.