Zend Framework database initialisation - database

in tutorials such as this http://akrabat.com/zend-framework-tutorial/, the database parameters for the application are stored in the application.ini config file. Reading through the docs for zend_db and other database interaction tutorials, it suggests that the database object is created from parameters hard coded into php code. Whats confusing is that there doesnt appear to be any explicit initialisation of the database object in tutorials such as the one above. So my natural conclusion to this is that the database object is automatically generated from the parameters provided in the application.ini config file?

So my natural conclusion to this is
that the database object is
automatically generated from the
parameters provided in the
application.ini config file?
Kind of, in fact, there are a few step before your database get initialized.
Your application is bootstraped
It reads the config file
When a resource.* is found, check if the according resource class exists
The resource class initialize an object with the given parameter
Zend_Db_Table has a static method setDefaultAdapter($db) which takes the newly created Zend_Db object, now every Zend_Db_table object can use the Db object you set in your configuration.
Return the newly created object
Go back to 3.
Router, Controller, Layout, View, etc.
This "behavior" is recent, it's why you may found some old tutorial which shows you how to bootstrap your Zend_Db object manually, sometimes, it's just to show you how Zend_Db works.

Related

What is the correct way to configure App.Config files when using wcf services

Let's say that I have a simple WPF or Winforms solution. To that solution I add a new project (based on a class library template , which I then reference in the main project) which is intended to be a data layer containing an entity framework data model. When I create the data model in the new project the connection string that it uses gets added to the app.config file of the main project in the solution.
Now let us say that I want to add two more projects to the solution (both of which will again be based on class libraries) to contain details of WCF services that I wish to use. In each case I add the WCF service by using the ADD Service Reference option from the right click context menu of the projects.
Unlike the data model project though the bindings for the service model get added to the local projects app.config file ass opposed to the app.config file of the main start-up project.
Should I simply copy those bindings to the start-up project's app.config file, or should I copy and then delete, or in fact should I be doing something completely different. Thus far trying combination of the first two suggestions I get error messages connected with endpoint configuration, however my knowledge of WCF is not really sufficiently good to fully understand the MSDN articles that the error list points me to.
Note that if the service references are added to the main project I get no errors whatsoever, so I figure this must be a configuration problem of some description.
Would anyone be able to provide the correct procedure for adding projects that essentially contain no more than a WCF service reference to an existing visual studio solution.
Edit
The screenshot below shows my main app.cofig file after having copied over the bindings configurations from the two service contracts. I'm not sure whether I should have commented out the bit that I did or not, I had thought that by doing so I might get rid of the blue squiggly underlines telling me the following (which I must admit to not understanding):
Warning The 'contract' attribute is invalid - The value 'ErsLiveService.IERSAPIService' is invalid according to its datatype 'clientContractType' - The Enumeration constraint failed.
You're likely getting the blue squigglies because the namespace ErsTestService is defined within the project in which you created the service reference. If the root namespace of that project is MyServiceReferenceProject then try changing the namespace to MyServiceReferenceProject.ErsTestService.IERSAPIService.

Finding out if one annotated variable in Dart has been accessed/mutated?

Looking at resources and documentation online, I have found out that you can access metadata annotations from classes or fields (How do I access metadata annotations from a class? or How to get the value from metadata, in Dart?, for instance).
But I would like to know how to see, after a variable has been annotated with a metadata annotation (such as #Persist), if that variable has been accessed or changed. That I wasn't able to find how to do it.
The application I have in mind for this is to be able to make a variable to transparently persist to a database (whenever the variable is accessed or mutated) by means of annotating that variable. Many thanks!
I think the observable package does what you want
see How to share data structures with Polymer on both client and server for an example

CakePHP Model with $useTable = false still tries to connect to database

I'm trying to develop an application that does not use a database, but that still has some models.
First problem: Cake look however for the configuration of the database (APP/Lib/Cake/Model/ConnectionManager.php, line 69), it tries to include the file Config/database.php.
If the file doesn't exist, I get 2 warnings. If it exists (even if it is completely empty) all ok. I want to clarify that this takes place even in the absence of models.
Second problem: if I try to use a model, I get the error:
Missing Datasource Configuration
Error: The datasource configuration default was not found in database.php.
This happens whether the Config/database.php file exists, whether the file is not present.
Finally, I specify that models (including the AppModel) have the property $useTable set to false, but it seems that it makes no difference.
But I have noticed that everything works correctly when in an application that uses a database there are only a few models that do not use it (but the app as a whole uses it).
I found this which proposes a solution, which then is the solution that is found on the web.
But below, in the comments, I read that Lorenzo says:
This does not make any sense at all, CakePHP 2.0 will not try to
perform any datbase connection unless you request it to do so
It seems to me that it has not, maybe CakePHP does not perform any query but still want a database is configured. Is that so? Or I missed something?
Thank you.
Possible causes
CakePHP doesn't try to connect to the database until it is actually required, however;
The app/Config/database.php file should always be present, even if you're not using a database. However, you don't have to 'configure' the various connections if you're not using them
If your models use behaviors, it's possible that database-calls are made by the behavior, causing CakePHP to attempt to connect to the database
Various methods inside the Model class will make connections to the database (e.g. requesting the 'schema' or 'columnType'.
Non-existing Model-methods will be mapped to a magic __call() method; This method will first check if a Behavior is able to handle the call, and otherwise will make a call to the database. E.g. using $this->Mymodel->doSomething() will cause CakePHP to attempt to open a database connection and execute doSomething in the database.
If a Model doesn't exist, CakePHP will create one, basically, it creates an instance of Model, using schema information from the database, causing a connection to be opened.
Example
class PostsController extends AppController {
// This controller does not use a Model
public $uses = false;
public function index() {
// CakePHP will construct a 'Post' model here
$this->Post->find('something');
}
}
Datasources, even if no database is used
Having said that. In most cases, it's best to have your models use a datasource; A datasource does not have to be a database, but may also be, for example, a Twitter Feed or a static Array().
Having a datasource simplifies most tasks (e.g. you can just perform find(....) to get the data from your source, whether that is a database or not.

How do I use the CakePHP Configure class?

I am trying to use the Configure class in CakePHP, but I'm not sure if I am using it correctly. I have read through the cook book and the API, but I can't seem to do what I want.
I have created a configuration file: app/config/config.php. I can directly edit this file and set variables in there and access them using Configure::read().
Is it possible to update the values of the configuration file from the application itself, i.e., from a controller? I have tried using Configure::write(), but this does not seem to change the value.
app/config/config.php isn't a file that's automatically loaded by Cake. Either move these variables into app/config/bootstrap.php or tell your bootstrap.php file to load your custom file. You could also put your variables in app/config/core.php, but I'd recommend against that. I tend to like leaving that file alone and adding/overwriting values in bootstrap.php.
According to the API, Configure is supposed to be used "for managing runtime configuration information".
You can use its methods to create, read, update and delete (CRUD) configuration variables at runtime. The Configure class is available everywhere in your CakePHP application and therefore CRUD operations performed on its data in any place, including a controller.
If you are looking for persistent storage, you could consider a database (SQL or NoSQL). I would not recommend using a text file, as it raises a lot of security concerns. Even if security is not an issue, a database is propably a more fitting solution.
More on the Configure class in the Cookbook.

Renaming CoreData classes while allowing App updates

I have made the mistake when starting the coding an iPhone App of not adding a prefix to my classnames, and as such have a conflict (A CoreData class called Category). The project build fine until the recent update of Xcode, and only now I realize the mistake.
Is it possible to rename CoreData classes while keeping a working system after update?
If I add a new version to the Datamodel and rename the class, the App updates, but it seems that the old table is deleted and a new (empty) one created. Obviously all the links subsequently are broken. I would like to maintain the data while making the change.
In Java EE you can overrule the table name if I remember correctly, and as such I could stick to the old class name to name the table. Is there any such possibility with CoreData?
Thanks in advance! I have to find a way to update the DB without all the Apps out in the field breaking.
Actually, it i documented quite well by Apple:
If you rename an entity or property,
you can set the renaming identifier in
the destination model to the name of
the corresponding property or entity
in the source model. You typically set
the renaming identifier using the
Xcode Data Modeling tool, (for either
an NSEntityDescription or an
NSPropertyDescription object). In
Xcode, the renaming identifier is in
the User Info pane of the Detail Pane,
below the version hash modifier (see
The Browser View in Xcode Tools for
Core Data). (Mac OS X Developer Library )
But actually for me it seems to work just to change the Classname and leave the rest of the model alone.

Resources